diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/services/groups | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/services/groups')
-rw-r--r-- | spec/services/groups/group_links/create_service_spec.rb | 1 | ||||
-rw-r--r-- | spec/services/groups/transfer_service_spec.rb | 69 | ||||
-rw-r--r-- | spec/services/groups/update_service_spec.rb | 48 |
3 files changed, 118 insertions, 0 deletions
diff --git a/spec/services/groups/group_links/create_service_spec.rb b/spec/services/groups/group_links/create_service_spec.rb index bca03863d1e..fb88433d8f6 100644 --- a/spec/services/groups/group_links/create_service_spec.rb +++ b/spec/services/groups/group_links/create_service_spec.rb @@ -25,6 +25,7 @@ RSpec.describe Groups::GroupLinks::CreateService, '#execute' do expires_at: nil } end + let(:user) { group_user } subject { described_class.new(group, user, opts) } diff --git a/spec/services/groups/transfer_service_spec.rb b/spec/services/groups/transfer_service_spec.rb index c87fc7d941e..89e4d091ff7 100644 --- a/spec/services/groups/transfer_service_spec.rb +++ b/spec/services/groups/transfer_service_spec.rb @@ -8,6 +8,75 @@ RSpec.describe Groups::TransferService do let!(:group_member) { create(:group_member, :owner, group: group, user: user) } let(:transfer_service) { described_class.new(group, user) } + context 'handling packages' do + let_it_be(:group) { create(:group, :public) } + let(:project) { create(:project, :public, namespace: group) } + let(:new_group) { create(:group, :public) } + + before do + group.add_owner(user) + new_group&.add_owner(user) + end + + context 'with an npm package' do + before do + create(:npm_package, project: project) + end + + shared_examples 'transfer not allowed' do + it 'does not allow transfer when there is a root namespace change' do + transfer_service.execute(new_group) + + expect(transfer_service.error).to eq('Transfer failed: Group contains projects with NPM packages.') + expect(group.parent).not_to eq(new_group) + end + end + + it_behaves_like 'transfer not allowed' + + context 'with a project within subgroup' do + let(:root_group) { create(:group) } + let(:group) { create(:group, parent: root_group) } + + before do + root_group.add_owner(user) + end + + it_behaves_like 'transfer not allowed' + + context 'without a root namespace change' do + let(:new_group) { create(:group, parent: root_group) } + + it 'allows transfer' do + transfer_service.execute(new_group) + + expect(transfer_service.error).to be nil + expect(group.parent).to eq(new_group) + end + end + + context 'when transferring a group into a root group' do + let(:new_group) { nil } + + it_behaves_like 'transfer not allowed' + end + end + end + + context 'without an npm package' do + context 'when transferring a group into a root group' do + let(:group) { create(:group, parent: create(:group)) } + + it 'allows transfer' do + transfer_service.execute(nil) + + expect(transfer_service.error).to be nil + expect(group.parent).to be_nil + end + end + end + end + shared_examples 'ensuring allowed transfer for a group' do context "when there's an exception on GitLab shell directories" do let(:new_parent_group) { create(:group, :public) } diff --git a/spec/services/groups/update_service_spec.rb b/spec/services/groups/update_service_spec.rb index 25c79d9e600..1e6a8d53354 100644 --- a/spec/services/groups/update_service_spec.rb +++ b/spec/services/groups/update_service_spec.rb @@ -9,6 +9,50 @@ RSpec.describe Groups::UpdateService do let!(:public_group) { create(:group, :public) } describe "#execute" do + shared_examples 'with packages' do + before do + group.add_owner(user) + end + + context 'with npm packages' do + let!(:package) { create(:npm_package, project: project) } + + it 'does not allow a path update' do + expect(update_group(group, user, path: 'updated')).to be false + expect(group.errors[:path]).to include('cannot change when group contains projects with NPM packages') + end + + it 'allows name update' do + expect(update_group(group, user, name: 'Updated')).to be true + expect(group.errors).to be_empty + expect(group.name).to eq('Updated') + end + end + end + + context 'with project' do + let!(:group) { create(:group, :public) } + let(:project) { create(:project, namespace: group) } + + it_behaves_like 'with packages' + + context 'located in a subgroup' do + let(:subgroup) { create(:group, parent: group) } + let!(:project) { create(:project, namespace: subgroup) } + + before do + subgroup.add_owner(user) + end + + it_behaves_like 'with packages' + + it 'does allow a path update if there is not a root namespace change' do + expect(update_group(subgroup, user, path: 'updated')).to be true + expect(subgroup.errors[:path]).to be_empty + end + end + end + context "project visibility_level validation" do context "public group with public projects" do let!(:service) { described_class.new(public_group, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL) } @@ -238,4 +282,8 @@ RSpec.describe Groups::UpdateService do end end end + + def update_group(group, user, opts) + Groups::UpdateService.new(group, user, opts).execute + end end |