2017-08-22 06:13:25 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Groups::NestedCreateService do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject(:service) { described_class.new(user, params) }
|
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
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
|
2017-08-22 06:13:25 -04:00
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
expect(group.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
|
2017-08-22 06:13:25 -04:00
|
|
|
end
|
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
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
|
2017-08-22 06:13:25 -04:00
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
expect(group.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
end
|
2017-08-22 06:13:25 -04:00
|
|
|
end
|
2017-08-25 06:35:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'without subgroups' do
|
|
|
|
let(:params) { { group_path: 'a-group' } }
|
2017-08-22 06:13:25 -04:00
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
before do
|
|
|
|
allow(Group).to receive(:supports_nested_groups?) { false }
|
|
|
|
end
|
2017-08-22 06:13:25 -04:00
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
it 'creates the group' do
|
|
|
|
group = service.execute
|
2017-08-22 06:13:25 -04:00
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
expect(group).to be_persisted
|
2017-08-22 06:13:25 -04:00
|
|
|
end
|
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
it 'returns the group if it already existed' do
|
|
|
|
existing_group = create(:group, path: 'a-group')
|
2017-08-22 06:13:25 -04:00
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
expect(service.execute).to eq(existing_group)
|
|
|
|
end
|
2017-08-22 06:13:25 -04:00
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
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')
|
2017-08-22 06:13:25 -04:00
|
|
|
end
|
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
it_behaves_like 'with a visibility level'
|
|
|
|
end
|
2017-08-22 06:13:25 -04:00
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
describe 'with subgroups', :nested_groups do
|
|
|
|
let(:params) { { group_path: 'a-group/a-sub-group' } }
|
2017-08-22 06:13:25 -04:00
|
|
|
|
2017-08-25 06:35:47 -04:00
|
|
|
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)
|
2017-08-22 06:13:25 -04:00
|
|
|
end
|
2017-08-25 06:35:47 -04:00
|
|
|
|
|
|
|
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'
|
2017-08-22 06:13:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|