diff options
Diffstat (limited to 'spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb')
-rw-r--r-- | spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb b/spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb new file mode 100644 index 00000000000..f42033fdb9c --- /dev/null +++ b/spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Users::MigrateRecordsToGhostUserInBatchesWorker do + include ExclusiveLeaseHelpers + + let(:worker) { described_class.new } + + describe '#perform', :clean_gitlab_redis_shared_state do + it 'executes service with lease' do + lease_key = described_class.name.underscore + + expect_to_obtain_exclusive_lease(lease_key, 'uuid') + expect_next_instance_of(Users::MigrateRecordsToGhostUserInBatchesService) do |service| + expect(service).to receive(:execute).and_return(true) + end + + worker.perform + end + end + + include_examples 'an idempotent worker' do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, namespace: create(:group)) } + let_it_be(:issue) { create(:issue, project: project, author: user, last_edited_by: user) } + + subject { worker.perform } + + before do + create(:ghost_user_migration, user: user, initiator_user: user) + end + + it 'migrates issue to ghost user' do + subject + + expect(issue.reload.author).to eq(User.ghost) + expect(issue.last_edited_by).to eq(User.ghost) + end + end + + context 'when user_destroy_with_limited_execution_time_worker is disabled' do + before do + stub_feature_flags(user_destroy_with_limited_execution_time_worker: false) + end + + it 'does not execute the service' do + expect(Users::MigrateRecordsToGhostUserInBatchesService).not_to receive(:new) + + worker.perform + end + end +end |