summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-20 10:53:52 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-20 10:53:52 +0200
commit841de9752fb35b7d1a701da8764729ba334c2da5 (patch)
tree715bc26217bad8bb54aaa4e1e5204f24f21b7c28 /spec
parent98f5c00e7ac860c7ac78b8245b171f2f27681563 (diff)
downloadgitlab-ce-841de9752fb35b7d1a701da8764729ba334c2da5.tar.gz
Fix background migration cleanup specs
We need to use a spy because an `after` RSpec hook is also going to call the migration we want to test, so we need to use `have_received` expectation. See gitlab-org/gitlab-ce#35351 for more details.
Diffstat (limited to 'spec')
-rw-r--r--spec/migrations/clean_stage_id_reference_migration_spec.rb22
1 files changed, 13 insertions, 9 deletions
diff --git a/spec/migrations/clean_stage_id_reference_migration_spec.rb b/spec/migrations/clean_stage_id_reference_migration_spec.rb
index c2072f2672d..9a581df28a2 100644
--- a/spec/migrations/clean_stage_id_reference_migration_spec.rb
+++ b/spec/migrations/clean_stage_id_reference_migration_spec.rb
@@ -2,28 +2,32 @@ require 'spec_helper'
require Rails.root.join('db', 'migrate', '20170710083355_clean_stage_id_reference_migration.rb')
describe CleanStageIdReferenceMigration, :migration, :sidekiq, :redis do
- let(:migration) { 'MigrateBuildStageIdReference' }
+ let(:migration_class) { 'MigrateBuildStageIdReference' }
+ let(:migration) { spy('migration') }
+
+ before do
+ allow(Gitlab::BackgroundMigration.const_get(migration_class))
+ .to receive(:new).and_return(migration)
+ end
context 'when there are pending background migrations' do
it 'processes pending jobs synchronously' do
Sidekiq::Testing.disable! do
- BackgroundMigrationWorker.perform_in(2.minutes, migration, [1, 1])
- BackgroundMigrationWorker.perform_async(migration, [1, 1])
-
- expect(Gitlab::BackgroundMigration)
- .to receive(:perform).twice.and_call_original
+ BackgroundMigrationWorker.perform_in(2.minutes, migration_class, [1, 1])
+ BackgroundMigrationWorker.perform_async(migration_class, [1, 1])
migrate!
+
+ expect(migration).to have_received(:perform).with(1, 1).twice
end
end
end
-
context 'when there are no background migrations pending' do
it 'does nothing' do
Sidekiq::Testing.disable! do
- expect(Gitlab::BackgroundMigration).not_to receive(:perform)
-
migrate!
+
+ expect(migration).not_to have_received(:perform)
end
end
end