diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-26 09:07:52 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-26 09:07:52 +0000 |
commit | 7e019504f5ac6decde690565857238e7e59aa034 (patch) | |
tree | fab8832b40e25fc9bc1ae54b9303b95ea146b5d5 /spec/workers | |
parent | 116d4e56e83a1f408afe710ce070e699ba206475 (diff) | |
download | gitlab-ce-7e019504f5ac6decde690565857238e7e59aa034.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/cluster_update_app_worker_spec.rb | 15 | ||||
-rw-r--r-- | spec/workers/update_highest_role_worker_spec.rb | 64 |
2 files changed, 74 insertions, 5 deletions
diff --git a/spec/workers/cluster_update_app_worker_spec.rb b/spec/workers/cluster_update_app_worker_spec.rb index e540ede4bc0..d91104334e5 100644 --- a/spec/workers/cluster_update_app_worker_spec.rb +++ b/spec/workers/cluster_update_app_worker_spec.rb @@ -47,11 +47,11 @@ describe ClusterUpdateAppWorker do end context 'with exclusive lease' do + let_it_be(:user) { create(:user) } let(:application) { create(:clusters_applications_prometheus, :installed) } let(:lease_key) { "#{described_class.name.underscore}-#{application.id}" } before do - allow(Gitlab::ExclusiveLease).to receive(:new) stub_exclusive_lease_taken(lease_key) end @@ -61,8 +61,10 @@ describe ClusterUpdateAppWorker do subject.perform(application.name, application.id, project.id, Time.now) end - it 'does not allow same app to be updated concurrently by different project' do - project1 = create(:project) + it 'does not allow same app to be updated concurrently by different project', :aggregate_failures do + stub_exclusive_lease("refresh_authorized_projects:#{user.id}") + stub_exclusive_lease("update_highest_role:#{user.id}") + project1 = create(:project, namespace: create(:namespace, owner: user)) expect(Clusters::Applications::PrometheusUpdateService).not_to receive(:new) @@ -81,10 +83,13 @@ describe ClusterUpdateAppWorker do subject.perform(application2.name, application2.id, project.id, Time.now) end - it 'allows different app to be updated by different project' do + it 'allows different app to be updated by different project', :aggregate_failures do application2 = create(:clusters_applications_prometheus, :installed) lease_key2 = "#{described_class.name.underscore}-#{application2.id}" - project2 = create(:project) + + stub_exclusive_lease("refresh_authorized_projects:#{user.id}") + stub_exclusive_lease("update_highest_role:#{user.id}") + project2 = create(:project, namespace: create(:namespace, owner: user)) stub_exclusive_lease(lease_key2) diff --git a/spec/workers/update_highest_role_worker_spec.rb b/spec/workers/update_highest_role_worker_spec.rb new file mode 100644 index 00000000000..cb112ebe07e --- /dev/null +++ b/spec/workers/update_highest_role_worker_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe UpdateHighestRoleWorker, :clean_gitlab_redis_shared_state do + include ExclusiveLeaseHelpers + + let(:worker) { described_class.new } + + describe '#perform' do + let(:active_scope_attributes) do + { + state: 'active', + ghost: false, + user_type: nil + } + end + let(:user) { create(:user, attributes) } + + subject { worker.perform(user.id) } + + context 'when user is found' do + let(:attributes) { active_scope_attributes } + + it 'updates the highest role for the user' do + user_highest_role = create(:user_highest_role, user: user) + create(:group_member, :developer, user: user) + + expect { subject } + .to change { user_highest_role.reload.highest_access_level } + .from(nil) + .to(Gitlab::Access::DEVELOPER) + end + end + + context 'when user is not found' do + shared_examples 'no update' do + it 'does not update any highest role' do + expect(Users::UpdateHighestMemberRoleService).not_to receive(:new) + + worker.perform(user.id) + end + end + + context 'when user is blocked' do + let(:attributes) { active_scope_attributes.merge(state: 'blocked') } + + it_behaves_like 'no update' + end + + context 'when user is a ghost' do + let(:attributes) { active_scope_attributes.merge(ghost: true) } + + it_behaves_like 'no update' + end + + context 'when user has a user type' do + let(:attributes) { active_scope_attributes.merge(user_type: :alert_bot) } + + it_behaves_like 'no update' + end + end + end +end |