summaryrefslogtreecommitdiff
path: root/spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb
blob: f42033fdb9c74f88e8eea7643e02c4b311ea1742 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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