diff options
Diffstat (limited to 'spec/models/project_authorization_spec.rb')
-rw-r--r-- | spec/models/project_authorization_spec.rb | 77 |
1 files changed, 55 insertions, 22 deletions
diff --git a/spec/models/project_authorization_spec.rb b/spec/models/project_authorization_spec.rb index 55fe28ceb6f..df89e97a41f 100644 --- a/spec/models/project_authorization_spec.rb +++ b/spec/models/project_authorization_spec.rb @@ -86,6 +86,25 @@ RSpec.describe ProjectAuthorization do end end + shared_examples_for 'does not log any detail' do + it 'does not log any detail' do + expect(Gitlab::AppLogger).not_to receive(:info) + + execute + end + end + + shared_examples_for 'logs the detail' do + it 'logs the detail' do + expect(Gitlab::AppLogger).to receive(:info).with( + entire_size: 3, + message: 'Project authorizations refresh performed with delay' + ) + + execute + end + end + describe '.insert_all_in_batches' do let_it_be(:user) { create(:user) } let_it_be(:project_1) { create(:project) } @@ -100,6 +119,8 @@ RSpec.describe ProjectAuthorization do ] end + subject(:execute) { described_class.insert_all_in_batches(attributes, per_batch_size) } + before do # Configure as if a replica database is enabled allow(::Gitlab::Database::LoadBalancing).to receive(:primary_only?).and_return(false) @@ -110,7 +131,7 @@ RSpec.describe ProjectAuthorization do specify do expect(described_class).not_to receive(:sleep) - described_class.insert_all_in_batches(attributes, per_batch_size) + execute expect(user.project_authorizations.pluck(:user_id, :project_id, :access_level)).to match_array(attributes.map(&:values)) end @@ -123,11 +144,13 @@ RSpec.describe ProjectAuthorization do expect(described_class).to receive(:insert_all).twice.and_call_original expect(described_class).to receive(:sleep).twice - described_class.insert_all_in_batches(attributes, per_batch_size) + execute expect(user.project_authorizations.pluck(:user_id, :project_id, :access_level)).to match_array(attributes.map(&:values)) end + it_behaves_like 'logs the detail' + context 'when the GitLab installation does not have a replica database configured' do before do # Configure as if a replica database is not enabled @@ -135,6 +158,7 @@ RSpec.describe ProjectAuthorization do end it_behaves_like 'inserts the rows in batches, as per the `per_batch` size, without a delay between each batch' + it_behaves_like 'does not log any detail' end end @@ -142,6 +166,7 @@ RSpec.describe ProjectAuthorization do let(:per_batch_size) { 5 } it_behaves_like 'inserts the rows in batches, as per the `per_batch` size, without a delay between each batch' + it_behaves_like 'does not log any detail' end end @@ -154,6 +179,14 @@ RSpec.describe ProjectAuthorization do let(:user_ids) { [user_1.id, user_2.id, user_3.id] } + subject(:execute) do + described_class.delete_all_in_batches_for_project( + project: project, + user_ids: user_ids, + per_batch: per_batch_size + ) + end + before do # Configure as if a replica database is enabled allow(::Gitlab::Database::LoadBalancing).to receive(:primary_only?).and_return(false) @@ -171,11 +204,7 @@ RSpec.describe ProjectAuthorization do specify do expect(described_class).not_to receive(:sleep) - described_class.delete_all_in_batches_for_project( - project: project, - user_ids: user_ids, - per_batch: per_batch_size - ) + execute expect(project.project_authorizations.pluck(:user_id)).not_to include(*user_ids) end @@ -187,15 +216,13 @@ RSpec.describe ProjectAuthorization do it 'removes the project authorizations of the specified users in the current project, with a delay between each batch' do expect(described_class).to receive(:sleep).twice - described_class.delete_all_in_batches_for_project( - project: project, - user_ids: user_ids, - per_batch: per_batch_size - ) + execute expect(project.project_authorizations.pluck(:user_id)).not_to include(*user_ids) end + it_behaves_like 'logs the detail' + context 'when the GitLab installation does not have a replica database configured' do before do # Configure as if a replica database is not enabled @@ -203,6 +230,7 @@ RSpec.describe ProjectAuthorization do end it_behaves_like 'removes the project authorizations of the specified users in the current project, without a delay between each batch' + it_behaves_like 'does not log any detail' end end @@ -210,6 +238,7 @@ RSpec.describe ProjectAuthorization do let(:per_batch_size) { 5 } it_behaves_like 'removes the project authorizations of the specified users in the current project, without a delay between each batch' + it_behaves_like 'does not log any detail' end end @@ -222,6 +251,14 @@ RSpec.describe ProjectAuthorization do let(:project_ids) { [project_1.id, project_2.id, project_3.id] } + subject(:execute) do + described_class.delete_all_in_batches_for_user( + user: user, + project_ids: project_ids, + per_batch: per_batch_size + ) + end + before do # Configure as if a replica database is enabled allow(::Gitlab::Database::LoadBalancing).to receive(:primary_only?).and_return(false) @@ -239,11 +276,7 @@ RSpec.describe ProjectAuthorization do specify do expect(described_class).not_to receive(:sleep) - described_class.delete_all_in_batches_for_user( - user: user, - project_ids: project_ids, - per_batch: per_batch_size - ) + execute expect(user.project_authorizations.pluck(:project_id)).not_to include(*project_ids) end @@ -255,15 +288,13 @@ RSpec.describe ProjectAuthorization do it 'removes the project authorizations of the specified projects from the current user, with a delay between each batch' do expect(described_class).to receive(:sleep).twice - described_class.delete_all_in_batches_for_user( - user: user, - project_ids: project_ids, - per_batch: per_batch_size - ) + execute expect(user.project_authorizations.pluck(:project_id)).not_to include(*project_ids) end + it_behaves_like 'logs the detail' + context 'when the GitLab installation does not have a replica database configured' do before do # Configure as if a replica database is not enabled @@ -271,6 +302,7 @@ RSpec.describe ProjectAuthorization do end it_behaves_like 'removes the project authorizations of the specified projects from the current user, without a delay between each batch' + it_behaves_like 'does not log any detail' end end @@ -278,6 +310,7 @@ RSpec.describe ProjectAuthorization do let(:per_batch_size) { 5 } it_behaves_like 'removes the project authorizations of the specified projects from the current user, without a delay between each batch' + it_behaves_like 'does not log any detail' end end end |