diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /spec/finders/groups | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'spec/finders/groups')
-rw-r--r-- | spec/finders/groups/accepting_project_transfers_finder_spec.rb | 63 | ||||
-rw-r--r-- | spec/finders/groups/user_groups_finder_spec.rb | 112 |
2 files changed, 118 insertions, 57 deletions
diff --git a/spec/finders/groups/accepting_project_transfers_finder_spec.rb b/spec/finders/groups/accepting_project_transfers_finder_spec.rb new file mode 100644 index 00000000000..e73318c763f --- /dev/null +++ b/spec/finders/groups/accepting_project_transfers_finder_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Groups::AcceptingProjectTransfersFinder do + let_it_be(:user) { create(:user) } + let_it_be(:group_where_direct_owner) { create(:group) } + let_it_be(:subgroup_of_group_where_direct_owner) { create(:group, parent: group_where_direct_owner) } + let_it_be(:group_where_direct_maintainer) { create(:group) } + let_it_be(:group_where_direct_maintainer_but_cant_create_projects) do + create(:group, project_creation_level: Gitlab::Access::NO_ONE_PROJECT_ACCESS) + end + + let_it_be(:group_where_direct_developer) { create(:group) } + let_it_be(:shared_with_group_where_direct_owner_as_owner) { create(:group) } + let_it_be(:shared_with_group_where_direct_owner_as_guest) { create(:group) } + let_it_be(:shared_with_group_where_direct_owner_as_maintainer) { create(:group) } + let_it_be(:shared_with_group_where_direct_developer_as_owner) { create(:group) } + let_it_be(:subgroup_of_shared_with_group_where_direct_owner_as_maintainer) do + create(:group, parent: shared_with_group_where_direct_owner_as_maintainer) + end + + before do + group_where_direct_owner.add_owner(user) + group_where_direct_maintainer.add_maintainer(user) + group_where_direct_developer.add_developer(user) + + create(:group_group_link, :owner, + shared_with_group: group_where_direct_owner, + shared_group: shared_with_group_where_direct_owner_as_owner + ) + + create(:group_group_link, :guest, + shared_with_group: group_where_direct_owner, + shared_group: shared_with_group_where_direct_owner_as_guest + ) + + create(:group_group_link, :maintainer, + shared_with_group: group_where_direct_owner, + shared_group: shared_with_group_where_direct_owner_as_maintainer + ) + + create(:group_group_link, :owner, + shared_with_group: group_where_direct_developer, + shared_group: shared_with_group_where_direct_developer_as_owner + ) + end + + describe '#execute' do + subject(:result) { described_class.new(user).execute } + + it 'only returns groups where the user has access to transfer projects to' do + expect(result).to match_array([ + group_where_direct_owner, + subgroup_of_group_where_direct_owner, + group_where_direct_maintainer, + shared_with_group_where_direct_owner_as_owner, + shared_with_group_where_direct_owner_as_maintainer, + subgroup_of_shared_with_group_where_direct_owner_as_maintainer + ]) + end + end +end diff --git a/spec/finders/groups/user_groups_finder_spec.rb b/spec/finders/groups/user_groups_finder_spec.rb index 9339741da79..999079468e5 100644 --- a/spec/finders/groups/user_groups_finder_spec.rb +++ b/spec/finders/groups/user_groups_finder_spec.rb @@ -5,17 +5,19 @@ require 'spec_helper' RSpec.describe Groups::UserGroupsFinder do describe '#execute' do let_it_be(:user) { create(:user) } + let_it_be(:root_group) { create(:group, name: 'Root group', path: 'root-group') } let_it_be(:guest_group) { create(:group, name: 'public guest', path: 'public-guest') } - let_it_be(:private_maintainer_group) { create(:group, :private, name: 'b private maintainer', path: 'b-private-maintainer') } - let_it_be(:public_developer_group) { create(:group, project_creation_level: nil, name: 'c public developer', path: 'c-public-developer') } - let_it_be(:public_maintainer_group) { create(:group, name: 'a public maintainer', path: 'a-public-maintainer') } + let_it_be(:private_maintainer_group) { create(:group, :private, name: 'b private maintainer', path: 'b-private-maintainer', parent: root_group) } + let_it_be(:public_developer_group) { create(:group, project_creation_level: nil, name: 'c public developer', path: 'c-public-developer', parent: root_group) } + let_it_be(:public_maintainer_group) { create(:group, name: 'a public maintainer', path: 'a-public-maintainer', parent: root_group) } let_it_be(:public_owner_group) { create(:group, name: 'a public owner', path: 'a-public-owner') } - subject { described_class.new(current_user, target_user, arguments).execute } + subject { described_class.new(current_user, target_user, arguments.merge(search_arguments)).execute } let(:arguments) { {} } let(:current_user) { user } let(:target_user) { user } + let(:search_arguments) { {} } before_all do guest_group.add_guest(user) @@ -25,15 +27,40 @@ RSpec.describe Groups::UserGroupsFinder do public_owner_group.add_owner(user) end - it 'returns all groups where the user is a direct member' do - is_expected.to match( - [ + shared_examples 'user group finder searching by name or path' do + let(:search_arguments) { { search: 'maintainer' } } + + specify do + is_expected.to contain_exactly( public_maintainer_group, - public_owner_group, - private_maintainer_group, - public_developer_group, - guest_group - ] + private_maintainer_group + ) + end + + context 'when searching for a full path (including parent)' do + let(:search_arguments) { { search: 'root-group/b-private-maintainer' } } + + specify do + is_expected.to contain_exactly(private_maintainer_group) + end + end + + context 'when search keywords include the parent route' do + let(:search_arguments) { { search: 'root public' } } + + specify do + is_expected.to match(keyword_search_expected_groups) + end + end + end + + it 'returns all groups where the user is a direct member' do + is_expected.to contain_exactly( + public_maintainer_group, + public_owner_group, + private_maintainer_group, + public_developer_group, + guest_group ) end @@ -53,26 +80,20 @@ RSpec.describe Groups::UserGroupsFinder do let(:arguments) { { permission_scope: :create_projects } } specify do - is_expected.to match( + is_expected.to contain_exactly( + public_maintainer_group, + public_owner_group, + private_maintainer_group, + public_developer_group + ) + end + + it_behaves_like 'user group finder searching by name or path' do + let(:keyword_search_expected_groups) do [ public_maintainer_group, - public_owner_group, - private_maintainer_group, public_developer_group ] - ) - end - - context 'when search is provided' do - let(:arguments) { { permission_scope: :create_projects, search: 'maintainer' } } - - specify do - is_expected.to match( - [ - public_maintainer_group, - private_maintainer_group - ] - ) end end end @@ -81,38 +102,15 @@ RSpec.describe Groups::UserGroupsFinder do let(:arguments) { { permission_scope: :transfer_projects } } specify do - is_expected.to match( - [ - public_maintainer_group, - public_owner_group, - private_maintainer_group - ] + is_expected.to contain_exactly( + public_maintainer_group, + public_owner_group, + private_maintainer_group ) end - context 'when search is provided' do - let(:arguments) { { permission_scope: :transfer_projects, search: 'owner' } } - - specify do - is_expected.to match( - [ - public_owner_group - ] - ) - end - end - end - - context 'when search is provided' do - let(:arguments) { { search: 'maintainer' } } - - specify do - is_expected.to match( - [ - public_maintainer_group, - private_maintainer_group - ] - ) + it_behaves_like 'user group finder searching by name or path' do + let(:keyword_search_expected_groups) { [public_maintainer_group] } end end end |