summaryrefslogtreecommitdiff
path: root/spec/finders
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-13 15:08:02 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-13 15:08:02 +0000
commit4eeb6b0d16021ab4a730eec4610eff2606421147 (patch)
tree488db828fe58f1e80dc5415970e4c929db7e4c4b /spec/finders
parent8cc5f2790908ba9bb8eecba2b78a3c5a88c77b90 (diff)
downloadgitlab-ce-4eeb6b0d16021ab4a730eec4610eff2606421147.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders')
-rw-r--r--spec/finders/group_members_finder_spec.rb38
-rw-r--r--spec/finders/members_finder_spec.rb50
2 files changed, 77 insertions, 11 deletions
diff --git a/spec/finders/group_members_finder_spec.rb b/spec/finders/group_members_finder_spec.rb
index 08f3b4024b3..f161a1df9c3 100644
--- a/spec/finders/group_members_finder_spec.rb
+++ b/spec/finders/group_members_finder_spec.rb
@@ -3,12 +3,13 @@
require 'spec_helper'
describe GroupMembersFinder, '#execute' do
- let(:group) { create(:group) }
+ let(:group) { create(:group) }
let(:nested_group) { create(:group, parent: group) }
- let(:user1) { create(:user) }
- let(:user2) { create(:user) }
- let(:user3) { create(:user) }
- let(:user4) { create(:user) }
+ let(:deeper_nested_group) { create(:group, parent: nested_group) }
+ let(:user1) { create(:user) }
+ let(:user2) { create(:user) }
+ let(:user3) { create(:user) }
+ let(:user4) { create(:user) }
it 'returns members for top-level group' do
member1 = group.add_maintainer(user1)
@@ -20,7 +21,7 @@ describe GroupMembersFinder, '#execute' do
expect(result.to_a).to match_array([member3, member2, member1])
end
- it 'returns members for nested group' do
+ it 'returns members & inherited members for nested group by default' do
group.add_developer(user2)
nested_group.request_access(user4)
member1 = group.add_maintainer(user1)
@@ -32,6 +33,29 @@ describe GroupMembersFinder, '#execute' do
expect(result.to_a).to match_array([member1, member3, member4])
end
+ it 'does not return inherited members for nested group if requested' do
+ group.add_maintainer(user1)
+ group.add_developer(user2)
+ member2 = nested_group.add_maintainer(user2)
+ member3 = nested_group.add_maintainer(user3)
+
+ result = described_class.new(nested_group).execute(include_relations: [:direct])
+
+ expect(result.to_a).to match_array([member2, member3])
+ end
+
+ it 'returns only inherited members for nested group if requested' do
+ group.add_developer(user2)
+ nested_group.request_access(user4)
+ member1 = group.add_maintainer(user1)
+ nested_group.add_maintainer(user2)
+ nested_group.add_maintainer(user3)
+
+ result = described_class.new(nested_group).execute(include_relations: [:inherited])
+
+ expect(result.to_a).to match_array([member1])
+ end
+
it 'returns members for descendant groups if requested' do
member1 = group.add_maintainer(user2)
member2 = group.add_maintainer(user1)
@@ -39,7 +63,7 @@ describe GroupMembersFinder, '#execute' do
member3 = nested_group.add_maintainer(user3)
member4 = nested_group.add_maintainer(user4)
- result = described_class.new(group).execute(include_descendants: true)
+ result = described_class.new(group).execute(include_relations: [:direct, :descendants])
expect(result.to_a).to match_array([member1, member2, member3, member4])
end
diff --git a/spec/finders/members_finder_spec.rb b/spec/finders/members_finder_spec.rb
index f9b8fee6f2d..2bc37606a25 100644
--- a/spec/finders/members_finder_spec.rb
+++ b/spec/finders/members_finder_spec.rb
@@ -22,22 +22,64 @@ describe MembersFinder, '#execute' do
expect(result).to contain_exactly(member1, member2, member3)
end
+ it 'includes only non-invite members if user do not have amdin permissions on project' do
+ create(:project_member, :invited, project: project, invite_email: create(:user).email)
+ member1 = project.add_maintainer(user1)
+ member2 = project.add_developer(user2)
+
+ result = described_class.new(project, user2).execute(include_relations: [:direct])
+
+ expect(result).to contain_exactly(member1, member2)
+ end
+
+ it 'includes invited members if user have admin permissions on project' do
+ member_invite = create(:project_member, :invited, project: project, invite_email: create(:user).email)
+ member1 = project.add_maintainer(user1)
+ member2 = project.add_maintainer(user2)
+
+ result = described_class.new(project, user2).execute(include_relations: [:direct])
+
+ expect(result).to contain_exactly(member1, member2, member_invite)
+ end
+
it 'includes nested group members if asked', :nested_groups do
nested_group.request_access(user1)
member1 = group.add_maintainer(user2)
member2 = nested_group.add_maintainer(user3)
member3 = project.add_maintainer(user4)
- result = described_class.new(project, user2).execute(include_descendants: true)
+ result = described_class.new(project, user2).execute(include_relations: [:direct, :descendants])
expect(result).to contain_exactly(member1, member2, member3)
end
+ it 'returns only members of project if asked' do
+ nested_group.request_access(user1)
+ group.add_maintainer(user2)
+ nested_group.add_maintainer(user3)
+ member4 = project.add_maintainer(user4)
+
+ result = described_class.new(project, user2).execute(include_relations: [:direct])
+
+ expect(result).to contain_exactly(member4)
+ end
+
+ it 'returns only inherited members of project if asked' do
+ nested_group.request_access(user1)
+ member2 = group.add_maintainer(user2)
+ member3 = nested_group.add_maintainer(user3)
+ project.add_maintainer(user4)
+
+ result = described_class.new(project, user2).execute(include_relations: [:inherited])
+
+ expect(result).to contain_exactly(member2, member3)
+ end
+
it 'returns the members.access_level when the user is invited', :nested_groups do
member_invite = create(:project_member, :invited, project: project, invite_email: create(:user).email)
member1 = group.add_maintainer(user2)
- result = described_class.new(project, user2).execute(include_descendants: true)
+ result = described_class.new(project, user2).execute(include_relations: [:direct, :descendants])
expect(result).to contain_exactly(member1, member_invite)
expect(result.last.access_level).to eq(member_invite.access_level)
@@ -48,14 +90,14 @@ describe MembersFinder, '#execute' do
group.add_developer(user1)
nested_group.add_reporter(user1)
- result = described_class.new(project, user1).execute(include_descendants: true)
+ result = described_class.new(project, user1).execute(include_relations: [:direct, :descendants])
expect(result).to contain_exactly(member1)
expect(result.first.access_level).to eq(Gitlab::Access::DEVELOPER)
end
context 'when include_invited_groups_members == true' do
- subject { described_class.new(project, user2).execute(include_invited_groups_members: true) }
+ subject { described_class.new(project, user2).execute(include_relations: [:inherited, :direct, :invited_groups_members]) }
set(:linked_group) { create(:group, :public) }
set(:nested_linked_group) { create(:group, parent: linked_group) }