summaryrefslogtreecommitdiff
path: root/spec/services/groups
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-08-25 12:35:47 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-08-25 12:35:47 +0200
commit529a07bd1e05a85b3cfa117ed8980ad64d997db0 (patch)
tree24177b653096f602ad97c29ea8b6c227945f2bf6 /spec/services/groups
parentec784b1e5195848e55185831ee024a756f18a9f0 (diff)
downloadgitlab-ce-529a07bd1e05a85b3cfa117ed8980ad64d997db0.tar.gz
Handle creating a nested group on MySQL correctlybvl-fix-mysql-bare-repository-importer
Since we don't support nested groups on MySQL, raise an error explaining that on import instead of trying anyway.
Diffstat (limited to 'spec/services/groups')
-rw-r--r--spec/services/groups/nested_create_service_spec.rb87
1 files changed, 61 insertions, 26 deletions
diff --git a/spec/services/groups/nested_create_service_spec.rb b/spec/services/groups/nested_create_service_spec.rb
index 6d11edb5842..6491fb34777 100644
--- a/spec/services/groups/nested_create_service_spec.rb
+++ b/spec/services/groups/nested_create_service_spec.rb
@@ -2,52 +2,87 @@ require 'spec_helper'
describe Groups::NestedCreateService do
let(:user) { create(:user) }
- let(:params) { { group_path: 'a-group/a-sub-group' } }
subject(:service) { described_class.new(user, params) }
- describe "#execute" do
- it 'returns the group if it already existed' do
- parent = create(:group, path: 'a-group', owner: user)
- child = create(:group, path: 'a-sub-group', parent: parent, owner: user)
+ shared_examples 'with a visibility level' do
+ it 'creates the group with correct visibility level' do
+ allow(Gitlab::CurrentSettings.current_application_settings)
+ .to receive(:default_group_visibility) { Gitlab::VisibilityLevel::INTERNAL }
+
+ group = service.execute
- expect(service.execute).to eq(child)
+ expect(group.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
end
- it 'reuses a parent if it already existed', :nested_groups do
- parent = create(:group, path: 'a-group')
- parent.add_owner(user)
+ context 'adding a visibility level ' do
+ it 'overwrites the visibility level' do
+ service = described_class.new(user, params.merge(visibility_level: Gitlab::VisibilityLevel::PRIVATE))
+
+ group = service.execute
- expect(service.execute.parent).to eq(parent)
+ expect(group.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
+ end
end
+ end
+
+ describe 'without subgroups' do
+ let(:params) { { group_path: 'a-group' } }
- it 'creates group and subgroup in the database', :nested_groups do
- service.execute
+ before do
+ allow(Group).to receive(:supports_nested_groups?) { false }
+ end
- parent = Group.find_by_full_path('a-group')
- child = parent.children.find_by(path: 'a-sub-group')
+ it 'creates the group' do
+ group = service.execute
- expect(parent).not_to be_nil
- expect(child).not_to be_nil
+ expect(group).to be_persisted
end
- it 'creates the group with correct visibility level' do
- allow(Gitlab::CurrentSettings.current_application_settings)
- .to receive(:default_group_visibility) { Gitlab::VisibilityLevel::INTERNAL }
+ it 'returns the group if it already existed' do
+ existing_group = create(:group, path: 'a-group')
- group = service.execute
+ expect(service.execute).to eq(existing_group)
+ end
- expect(group.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
+ it 'raises an error when tring to create a subgroup' do
+ service = described_class.new(user, group_path: 'a-group/a-sub-group')
+
+ expect { service.execute }.to raise_error('Nested groups are not supported on MySQL')
end
- context 'adding a visibility level ' do
- let(:params) { { group_path: 'a-group/a-sub-group', visibility_level: Gitlab::VisibilityLevel::PRIVATE } }
+ it_behaves_like 'with a visibility level'
+ end
- it 'overwrites the visibility level' do
- group = service.execute
+ describe 'with subgroups', :nested_groups do
+ let(:params) { { group_path: 'a-group/a-sub-group' } }
- expect(group.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
+ describe "#execute" do
+ it 'returns the group if it already existed' do
+ parent = create(:group, path: 'a-group', owner: user)
+ child = create(:group, path: 'a-sub-group', parent: parent, owner: user)
+
+ expect(service.execute).to eq(child)
end
+
+ it 'reuses a parent if it already existed' do
+ parent = create(:group, path: 'a-group')
+ parent.add_owner(user)
+
+ expect(service.execute.parent).to eq(parent)
+ end
+
+ it 'creates group and subgroup in the database' do
+ service.execute
+
+ parent = Group.find_by_full_path('a-group')
+ child = parent.children.find_by(path: 'a-sub-group')
+
+ expect(parent).not_to be_nil
+ expect(child).not_to be_nil
+ end
+
+ it_behaves_like 'with a visibility level'
end
end
end