diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 18:07:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 18:07:45 +0300 |
commit | 1219a9dce91f4edbc135dfc08299b4122b4825a8 (patch) | |
tree | e7d12a55d75a2d56e60d9527bef3724e3578866d /spec/workers/update_highest_role_worker_spec.rb | |
parent | 1a0d6dbdc2ac3047f4953a359ef27ba6e26074ae (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/update_highest_role_worker_spec.rb')
-rw-r--r-- | spec/workers/update_highest_role_worker_spec.rb | 87 |
1 files changed, 52 insertions, 35 deletions
diff --git a/spec/workers/update_highest_role_worker_spec.rb b/spec/workers/update_highest_role_worker_spec.rb index cb112ebe07e..1e378a5a61e 100644 --- a/spec/workers/update_highest_role_worker_spec.rb +++ b/spec/workers/update_highest_role_worker_spec.rb @@ -8,56 +8,73 @@ describe UpdateHighestRoleWorker, :clean_gitlab_redis_shared_state do let(:worker) { described_class.new } describe '#perform' do - let(:active_scope_attributes) do - { - state: 'active', - ghost: false, - user_type: nil - } + context 'when user is not found' do + it 'does not update or deletes any highest role', :aggregate_failures do + expect { worker.perform(-1) }.not_to change(UserHighestRole, :count) + end end - let(:user) { create(:user, attributes) } - - subject { worker.perform(user.id) } context 'when user is found' do - let(:attributes) { active_scope_attributes } + let(:active_attributes) do + { + state: 'active', + ghost: false, + user_type: nil + } + end + let(:user) { create(:user, active_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) + subject { worker.perform(user.id) } - expect { subject } - .to change { user_highest_role.reload.highest_access_level } - .from(nil) - .to(Gitlab::Access::DEVELOPER) - end - end + context 'when user is active and not internal' do + context 'when user highest role exists' do + it 'updates the highest role for the user' do + user_highest_role = create(:user_highest_role, user: user) + create(:group_member, :developer, user: user) - 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) + expect { subject } + .to change { user_highest_role.reload.highest_access_level } + .from(nil) + .to(Gitlab::Access::DEVELOPER) + end + end + + context 'when user highest role does not exist' do + it 'creates the highest role for the user' do + create(:group_member, :developer, user: user) - worker.perform(user.id) + expect { subject }.to change { UserHighestRole.count }.by(1) + end end end - context 'when user is blocked' do - let(:attributes) { active_scope_attributes.merge(state: 'blocked') } + context 'when user is either inactive or internal' do + using RSpec::Parameterized::TableSyntax - it_behaves_like 'no update' - end + where(:additional_attributes) do + [ + { state: 'blocked' }, + { ghost: true }, + { user_type: :alert_bot } + ] + end - context 'when user is a ghost' do - let(:attributes) { active_scope_attributes.merge(ghost: true) } + with_them do + it 'deletes highest role' do + user = create(:user, active_attributes.merge(additional_attributes)) + create(:user_highest_role, user: user) - it_behaves_like 'no update' - end + expect { worker.perform(user.id) }.to change { UserHighestRole.count }.from(1).to(0) + end + end - context 'when user has a user type' do - let(:attributes) { active_scope_attributes.merge(user_type: :alert_bot) } + context 'when user highest role does not exist' do + it 'does not delete a highest role' do + user = create(:user, state: 'blocked') - it_behaves_like 'no update' + expect { worker.perform(user.id) }.not_to change(UserHighestRole, :count) + end + end end end end |