Commit cd84ce1a authored by Sean McGivern's avatar Sean McGivern Committed by Ruben Davila

Don't depend on user model in migration spec

The User model now has a default value for a field that didn't exist when these
migrations ran.
parent c3ac7311
...@@ -215,9 +215,16 @@ end ...@@ -215,9 +215,16 @@ end
# to a specific version of the database where said table is still present. # to a specific version of the database where said table is still present.
# #
describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads, :migration, schema: 20170825154015 do describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads, :migration, schema: 20170825154015 do
let(:user_class) do
Class.new(ActiveRecord::Base) do
self.table_name = 'users'
end
end
let(:migration) { described_class.new } let(:migration) { described_class.new }
let(:project) { create(:project_empty_repo) } let(:author) { build(:user).becomes(user_class).tap(&:save!).becomes(User) }
let(:author) { create(:user) } let(:namespace) { create(:namespace, owner: author) }
let(:project) { create(:project_empty_repo, namespace: namespace, creator: author) }
# We can not rely on FactoryGirl as the state of Event may change in ways that # We can not rely on FactoryGirl as the state of Event may change in ways that
# the background migration does not expect, hence we use the Event class of # the background migration does not expect, hence we use the Event class of
......
...@@ -2,6 +2,12 @@ require 'spec_helper' ...@@ -2,6 +2,12 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170607121233_convert_custom_notification_settings_to_columns') require Rails.root.join('db', 'post_migrate', '20170607121233_convert_custom_notification_settings_to_columns')
describe ConvertCustomNotificationSettingsToColumns, :migration do describe ConvertCustomNotificationSettingsToColumns, :migration do
let(:user_class) do
Class.new(ActiveRecord::Base) do
self.table_name = 'users'
end
end
let(:settings_params) do let(:settings_params) do
[ [
{ level: 0, events: [:new_note] }, # disabled, single event { level: 0, events: [:new_note] }, # disabled, single event
...@@ -19,7 +25,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do ...@@ -19,7 +25,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do
events[event] = true events[event] = true
end end
user = create(:user) user = build(:user).becomes(user_class).tap(&:save!)
create_params = { user_id: user.id, level: params[:level], events: events } create_params = { user_id: user.id, level: params[:level], events: events }
notification_setting = described_class::NotificationSetting.create(create_params) notification_setting = described_class::NotificationSetting.create(create_params)
...@@ -35,7 +41,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do ...@@ -35,7 +41,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do
events[event] = true events[event] = true
end end
user = create(:user) user = build(:user).becomes(user_class).tap(&:save!)
create_params = events.merge(user_id: user.id, level: params[:level]) create_params = events.merge(user_id: user.id, level: params[:level])
notification_setting = described_class::NotificationSetting.create(create_params) notification_setting = described_class::NotificationSetting.create(create_params)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment