diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-06 15:10:04 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-06 15:10:04 +0000 |
commit | f3b1e07903a7f509b11ad7cf188fac46d98f77f6 (patch) | |
tree | a6fa5e65d83d94334387952f1f526ed438604408 /spec/models | |
parent | ba174c982f40d71a87fd511b091753807174f7e7 (diff) | |
download | gitlab-ce-f3b1e07903a7f509b11ad7cf188fac46d98f77f6.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/user_spec.rb | 100 |
1 files changed, 25 insertions, 75 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e69d4e18c1e..679f4a19f5b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -28,7 +28,6 @@ describe User, :do_not_mock_admin_mode do describe 'associations' do it { is_expected.to have_one(:namespace) } it { is_expected.to have_one(:status) } - it { is_expected.to have_one(:max_access_level_membership) } it { is_expected.to have_one(:user_detail) } it { is_expected.to have_one(:user_highest_role) } it { is_expected.to have_many(:snippets).dependent(:destroy) } @@ -1000,91 +999,42 @@ describe User, :do_not_mock_admin_mode do end describe '#highest_role' do - let(:user) { create(:user) } - let(:group) { create(:group) } - - context 'with association :max_access_level_membership' do - let(:another_user) { create(:user) } - - before do - create(:project, group: group) do |project| - group.add_user(user, GroupMember::GUEST) - group.add_user(another_user, GroupMember::DEVELOPER) - end - - create(:project, group: create(:group)) do |project| - project.add_guest(another_user) - end - - create(:project, group: create(:group)) do |project| - project.add_maintainer(user) - end - end - - it 'returns the correct highest role' do - users = User.includes(:max_access_level_membership).where(id: [user.id, another_user.id]) - - expect(users.collect { |u| [u.id, u.highest_role] }).to contain_exactly( - [user.id, Gitlab::Access::MAINTAINER], - [another_user.id, Gitlab::Access::DEVELOPER] - ) - end - end - - it 'returns NO_ACCESS if none has been set' do - expect(user.highest_role).to eq(Gitlab::Access::NO_ACCESS) - end - - it 'returns MAINTAINER if user is maintainer of a project' do - create(:project, group: group) do |project| - project.add_maintainer(user) - end - - expect(user.highest_role).to eq(Gitlab::Access::MAINTAINER) - end + let_it_be(:user) { create(:user) } - it 'returns the highest role if user is member of multiple projects' do - create(:project, group: group) do |project| - project.add_maintainer(user) + context 'when user_highest_role does not exist' do + it 'returns NO_ACCESS' do + expect(user.highest_role).to eq(Gitlab::Access::NO_ACCESS) end - - create(:project, group: group) do |project| - project.add_developer(user) - end - - expect(user.highest_role).to eq(Gitlab::Access::MAINTAINER) end - it 'returns MAINTAINER if user is maintainer of a group' do - create(:group) do |group| - group.add_user(user, GroupMember::MAINTAINER) - end - - expect(user.highest_role).to eq(Gitlab::Access::MAINTAINER) - end + context 'when user_highest_role exists' do + context 'stored highest access level is nil' do + it 'returns Gitlab::Access::NO_ACCESS' do + create(:user_highest_role, user: user) - it 'returns the highest role if user is member of multiple groups' do - create(:group) do |group| - group.add_user(user, GroupMember::MAINTAINER) + expect(user.highest_role).to eq(Gitlab::Access::NO_ACCESS) + end end - create(:group) do |group| - group.add_user(user, GroupMember::DEVELOPER) - end + context 'stored highest access level present' do + context 'with association :user_highest_role' do + let(:another_user) { create(:user) } - expect(user.highest_role).to eq(Gitlab::Access::MAINTAINER) - end + before do + create(:user_highest_role, :maintainer, user: user) + create(:user_highest_role, :developer, user: another_user) + end - it 'returns the highest role if user is member of multiple groups and projects' do - create(:group) do |group| - group.add_user(user, GroupMember::DEVELOPER) - end + it 'returns the correct highest role' do + users = User.includes(:user_highest_role).where(id: [user.id, another_user.id]) - create(:project, group: group) do |project| - project.add_maintainer(user) + expect(users.collect { |u| [u.id, u.highest_role] }).to contain_exactly( + [user.id, Gitlab::Access::MAINTAINER], + [another_user.id, Gitlab::Access::DEVELOPER] + ) + end + end end - - expect(user.highest_role).to eq(Gitlab::Access::MAINTAINER) end end |