diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-19 23:18:09 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-19 23:18:09 +0000 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/workers/users | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) | |
download | gitlab-ce-6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde.tar.gz |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/workers/users')
-rw-r--r-- | spec/workers/users/deactivate_dormant_users_worker_spec.rb | 10 | ||||
-rw-r--r-- | spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb | 53 |
2 files changed, 58 insertions, 5 deletions
diff --git a/spec/workers/users/deactivate_dormant_users_worker_spec.rb b/spec/workers/users/deactivate_dormant_users_worker_spec.rb index 263ca31e0a0..a8318de669b 100644 --- a/spec/workers/users/deactivate_dormant_users_worker_spec.rb +++ b/spec/workers/users/deactivate_dormant_users_worker_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Users::DeactivateDormantUsersWorker do using RSpec::Parameterized::TableSyntax describe '#perform' do - let_it_be(:dormant) { create(:user, last_activity_on: User::MINIMUM_INACTIVE_DAYS.days.ago.to_date) } + let_it_be(:dormant) { create(:user, last_activity_on: Gitlab::CurrentSettings.deactivate_dormant_users_period.days.ago.to_date) } let_it_be(:inactive) { create(:user, last_activity_on: nil, created_at: User::MINIMUM_DAYS_CREATED.days.ago.to_date) } let_it_be(:inactive_recently_created) { create(:user, last_activity_on: nil, created_at: (User::MINIMUM_DAYS_CREATED - 1).days.ago.to_date) } @@ -14,7 +14,7 @@ RSpec.describe Users::DeactivateDormantUsersWorker do it 'does not run for GitLab.com' do expect(Gitlab).to receive(:com?).and_return(true) - expect(Gitlab::CurrentSettings).not_to receive(:current_application_settings) + # Now makes a call to current settings to determine period of dormancy worker.perform @@ -48,7 +48,7 @@ RSpec.describe Users::DeactivateDormantUsersWorker do end with_them do it 'deactivates certain user types' do - user = create(:user, user_type: user_type, state: :active, last_activity_on: User::MINIMUM_INACTIVE_DAYS.days.ago.to_date) + user = create(:user, user_type: user_type, state: :active, last_activity_on: Gitlab::CurrentSettings.deactivate_dormant_users_period.days.ago.to_date) worker.perform @@ -57,8 +57,8 @@ RSpec.describe Users::DeactivateDormantUsersWorker do end it 'does not deactivate non-active users' do - human_user = create(:user, user_type: :human, state: :blocked, last_activity_on: User::MINIMUM_INACTIVE_DAYS.days.ago.to_date) - service_user = create(:user, user_type: :service_user, state: :blocked, last_activity_on: User::MINIMUM_INACTIVE_DAYS.days.ago.to_date) + human_user = create(:user, user_type: :human, state: :blocked, last_activity_on: Gitlab::CurrentSettings.deactivate_dormant_users_period.days.ago.to_date) + service_user = create(:user, user_type: :service_user, state: :blocked, last_activity_on: Gitlab::CurrentSettings.deactivate_dormant_users_period.days.ago.to_date) worker.perform 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 |