diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/helpers/admin | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/helpers/admin')
-rw-r--r-- | spec/helpers/admin/user_actions_helper_spec.rb | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/spec/helpers/admin/user_actions_helper_spec.rb b/spec/helpers/admin/user_actions_helper_spec.rb new file mode 100644 index 00000000000..7ccd9a4fe3e --- /dev/null +++ b/spec/helpers/admin/user_actions_helper_spec.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe Admin::UserActionsHelper do + describe '#admin_actions' do + let_it_be(:current_user) { build(:user) } + + subject { helper.admin_actions(user) } + + before do + allow(helper).to receive(:current_user).and_return(current_user) + allow(helper).to receive(:can?).with(current_user, :destroy_user, user).and_return(true) + end + + context 'the user is a bot' do + let_it_be(:user) { build(:user, :bot) } + + it { is_expected.to be_empty } + end + + context 'the current user and user are the same' do + let_it_be(:user) { build(:user) } + let_it_be(:current_user) { user } + + it { is_expected.to contain_exactly("edit") } + end + + context 'the user is a standard user' do + let_it_be(:user) { create(:user) } + + it { is_expected.to contain_exactly("edit", "block", "deactivate", "delete", "delete_with_contributions") } + end + + context 'the user is an admin user' do + let_it_be(:user) { create(:user, :admin) } + + it { is_expected.to contain_exactly("edit", "block", "deactivate", "delete", "delete_with_contributions") } + end + + context 'the user is blocked by LDAP' do + let_it_be(:user) { create(:omniauth_user, :ldap_blocked) } + + it { is_expected.to contain_exactly("edit", "ldap", "delete", "delete_with_contributions") } + end + + context 'the user is blocked pending approval' do + let_it_be(:user) { create(:user, :blocked_pending_approval) } + + it { is_expected.to contain_exactly("edit", "approve", "reject") } + end + + context 'the user is blocked' do + let_it_be(:user) { create(:user, :blocked) } + + it { is_expected.to contain_exactly("edit", "unblock", "delete", "delete_with_contributions") } + end + + context 'the user is deactivated' do + let_it_be(:user) { create(:user, :deactivated) } + + it { is_expected.to contain_exactly("edit", "block", "activate", "delete", "delete_with_contributions") } + end + + context 'the user is locked' do + let_it_be(:user) { create(:user) } + + before do + user.lock_access! + end + + it { + is_expected.to contain_exactly( + "edit", + "block", + "deactivate", + "unlock", + "delete", + "delete_with_contributions" + ) + } + end + + context 'the current_user does not have permission to delete the user' do + let_it_be(:user) { build(:user) } + + before do + allow(helper).to receive(:can?).with(current_user, :destroy_user, user).and_return(false) + end + + it { is_expected.to contain_exactly("edit", "block", "deactivate") } + end + + context 'the user is a sole owner of a group' do + let_it_be(:group) { create(:group) } + let_it_be(:user) { create(:user) } + + before do + group.add_owner(user) + end + + it { is_expected.to contain_exactly("edit", "block", "deactivate") } + end + end +end |