diff options
author | Regis <boudinot.regis@yahoo.com> | 2017-06-08 04:42:32 +0300 |
---|---|---|
committer | Regis <boudinot.regis@yahoo.com> | 2017-06-08 04:42:32 +0300 |
commit | 3b87edfaafa772d5c6a9276868b46a7929d55077 (patch) | |
tree | 582560f5fe65b8b4c3ab49fff866319b18265f54 /spec | |
parent | 6f2e590e8278eeb2cbb324c3990d6c65b277933c (diff) | |
parent | 7755c0b8b448721671e866f712898b247b02c2ac (diff) |
Merge remote-tracking branch 'gitlab/9-2-stable' into 9-2-stable
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/groups_controller_spec.rb | 9 | ||||
-rw-r--r-- | spec/finders/groups_finder_spec.rb | 37 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 13 |
3 files changed, 53 insertions, 6 deletions
diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 6b65e1c6cc5..3b4cb2357a0 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe GroupsController do let(:user) { create(:user) } - let(:group) { create(:group) } + let(:group) { create(:group, :public) } let(:project) { create(:empty_project, namespace: group) } let!(:group_member) { create(:group_member, group: group, user: user) } @@ -35,14 +35,15 @@ describe GroupsController do sign_in(user) end - it 'shows the public subgroups' do + it 'shows all subgroups' do get :subgroups, id: group.to_param - expect(assigns(:nested_groups)).to contain_exactly(public_subgroup) + expect(assigns(:nested_groups)).to contain_exactly(public_subgroup, private_subgroup) end - context 'being member' do + context 'being member of private subgroup' do it 'shows public and private subgroups the user is member of' do + group_member.destroy! private_subgroup.add_guest(user) get :subgroups, id: group.to_param diff --git a/spec/finders/groups_finder_spec.rb b/spec/finders/groups_finder_spec.rb index 5b3591550c1..e082631ce68 100644 --- a/spec/finders/groups_finder_spec.rb +++ b/spec/finders/groups_finder_spec.rb @@ -51,15 +51,48 @@ describe GroupsFinder do end context 'with a user' do + subject { described_class.new(user, parent: parent_group).execute } + it 'returns public and internal subgroups' do - expect(described_class.new(user, parent: parent_group).execute).to contain_exactly(public_subgroup, internal_subgroup) + is_expected.to contain_exactly(public_subgroup, internal_subgroup) end context 'being member' do it 'returns public subgroups, internal subgroups, and private subgroups user is member of' do private_subgroup.add_guest(user) - expect(described_class.new(user, parent: parent_group).execute).to contain_exactly(public_subgroup, internal_subgroup, private_subgroup) + is_expected.to contain_exactly(public_subgroup, internal_subgroup, private_subgroup) + end + end + + context 'parent group private' do + before do + parent_group.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PRIVATE) + end + + context 'being member of parent group' do + it 'returns all subgroups' do + parent_group.add_guest(user) + + is_expected.to contain_exactly(public_subgroup, internal_subgroup, private_subgroup) + end + end + + context 'authorized to private project' do + it 'returns the subgroup of the project' do + subproject = create(:empty_project, :private, namespace: private_subgroup) + subproject.add_guest(user) + + is_expected.to include(private_subgroup) + end + + it 'returns all the parent groups if project is several levels deep' do + private_subsubgroup = create(:group, :private, parent: private_subgroup) + subsubproject = create(:empty_project, :private, namespace: private_subsubgroup) + subsubproject.add_guest(user) + + expect(described_class.new(user).execute).to include(private_subsubgroup, private_subgroup, parent_group) + end end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 76a66888658..29ac82e004a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1251,6 +1251,19 @@ describe User, models: true do it { is_expected.to eq([private_group]) } end + describe '#groups_through_project_authorizations' do + it 'returns all groups being ancestor of the authorized project' do + user = create(:user) + group = create(:group, :private) + subgroup = create(:group, :private, parent: group) + subsubgroup = create(:group, :private, parent: subgroup) + project = create(:empty_project, :private, namespace: subsubgroup) + project.add_guest(user) + + expect(user.groups_through_project_authorizations).to contain_exactly(group, subgroup, subsubgroup) + end + end + describe '#authorized_projects', truncate: true do context 'with a minimum access level' do it 'includes projects for which the user is an owner' do |