diff options
Diffstat (limited to 'spec/requests/admin/background_migrations_controller_spec.rb')
-rw-r--r-- | spec/requests/admin/background_migrations_controller_spec.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/requests/admin/background_migrations_controller_spec.rb b/spec/requests/admin/background_migrations_controller_spec.rb new file mode 100644 index 00000000000..c7d5d5cae08 --- /dev/null +++ b/spec/requests/admin/background_migrations_controller_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Admin::BackgroundMigrationsController, :enable_admin_mode do + let(:admin) { create(:admin) } + + before do + sign_in(admin) + end + + describe 'POST #retry' do + let(:migration) { create(:batched_background_migration, status: 'failed') } + + before do + create(:batched_background_migration_job, batched_migration: migration, batch_size: 10, min_value: 6, max_value: 15, status: :failed, attempts: 3) + + allow_next_instance_of(Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy) do |batch_class| + allow(batch_class).to receive(:next_batch).with(anything, anything, batch_min_value: 6, batch_size: 5).and_return([6, 10]) + end + end + + subject(:retry_migration) { post retry_admin_background_migration_path(migration) } + + it 'redirects the user to the admin migrations page' do + retry_migration + + expect(response).to redirect_to(admin_background_migrations_path) + end + + it 'retries the migration' do + retry_migration + + expect(migration.reload.status).to eql 'active' + end + + context 'when the migration is not failed' do + let(:migration) { create(:batched_background_migration, status: 'paused') } + + it 'keeps the same migration status' do + expect { retry_migration }.not_to change { migration.reload.status } + end + end + end +end |