debian-mirror-gitlab/spec/requests/admin/background_migrations_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.5 KiB
Ruby
Raw Normal View History

2021-11-11 11:23:49 +05:30
# 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
2022-06-21 17:19:12 +05:30
let(:migration) { create(:batched_background_migration, :failed) }
2021-11-11 11:23:49 +05:30
before do
2022-04-04 11:22:00 +05:30
create(:batched_background_migration_job, :failed, batched_migration: migration, batch_size: 10, min_value: 6, max_value: 15, attempts: 3)
2021-11-11 11:23:49 +05:30
allow_next_instance_of(Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy) do |batch_class|
2022-05-07 20:08:51 +05:30
allow(batch_class).to receive(:next_batch).with(
anything,
anything,
batch_min_value: 6,
batch_size: 5,
job_arguments: migration.job_arguments
).and_return([6, 10])
2021-11-11 11:23:49 +05:30
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
2022-06-21 17:19:12 +05:30
expect(migration.reload.status_name).to be :active
2021-11-11 11:23:49 +05:30
end
context 'when the migration is not failed' do
2022-06-21 17:19:12 +05:30
let(:migration) { create(:batched_background_migration, :paused) }
2021-11-11 11:23:49 +05:30
it 'keeps the same migration status' do
expect { retry_migration }.not_to change { migration.reload.status }
end
end
end
end