2016-03-16 22:44:33 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-12-26 09:56:19 +00:00
|
|
|
describe Groups::CreateService, '#execute', services: true do
|
|
|
|
let!(:user) { create(:user) }
|
2016-03-18 12:28:16 +00:00
|
|
|
let!(:group_params) { { path: "group_path", visibility_level: Gitlab::VisibilityLevel::PUBLIC } }
|
2016-03-16 22:44:33 +00:00
|
|
|
|
2017-02-03 10:29:56 +00:00
|
|
|
subject { service.execute }
|
|
|
|
|
2016-12-26 09:56:19 +00:00
|
|
|
describe 'visibility level restrictions' do
|
|
|
|
let!(:service) { described_class.new(user, group_params) }
|
|
|
|
|
2016-03-16 22:44:33 +00:00
|
|
|
context "create groups without restricted visibility level" do
|
2016-03-17 22:42:46 +00:00
|
|
|
it { is_expected.to be_persisted }
|
2016-03-16 22:44:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "cannot create group with restricted visibility level" do
|
2016-05-28 02:05:52 +00:00
|
|
|
before { allow_any_instance_of(ApplicationSetting).to receive(:restricted_visibility_levels).and_return([Gitlab::VisibilityLevel::PUBLIC]) }
|
2016-12-26 09:56:19 +00:00
|
|
|
|
2016-05-23 23:37:59 +00:00
|
|
|
it { is_expected.not_to be_persisted }
|
2016-03-16 22:44:33 +00:00
|
|
|
end
|
|
|
|
end
|
2016-12-26 09:56:19 +00:00
|
|
|
|
|
|
|
describe 'creating subgroup' do
|
|
|
|
let!(:group) { create(:group) }
|
|
|
|
let!(:service) { described_class.new(user, group_params.merge(parent_id: group.id)) }
|
|
|
|
|
|
|
|
context 'as group owner' do
|
|
|
|
before { group.add_owner(user) }
|
|
|
|
|
|
|
|
it { is_expected.to be_persisted }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as guest' do
|
|
|
|
it 'does not save group and returns an error' do
|
|
|
|
is_expected.not_to be_persisted
|
|
|
|
expect(subject.errors[:parent_id].first).to eq('manage access required to create subgroup')
|
|
|
|
expect(subject.parent_id).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-03 10:29:56 +00:00
|
|
|
|
|
|
|
describe 'creating a mattermost team' do
|
|
|
|
let!(:params) { group_params.merge(create_chat_team: true) }
|
|
|
|
let!(:service) { described_class.new(user, params) }
|
|
|
|
|
2017-02-20 12:41:50 +00:00
|
|
|
it 'triggers the service' do
|
|
|
|
expect_any_instance_of(Mattermost::CreateTeamService).to receive(:execute)
|
2017-02-03 10:29:56 +00:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
2017-02-20 12:41:50 +00:00
|
|
|
|
|
|
|
it 'create the chat team with the group' do
|
|
|
|
allow_any_instance_of(Mattermost::Team).to receive(:create)
|
|
|
|
.and_return({ 'name' => 'tanuki', 'id' => 'lskdjfwlekfjsdifjj' })
|
|
|
|
|
|
|
|
expect { subject }.to change { ChatTeam.count }.from(0).to(1)
|
|
|
|
end
|
2017-02-03 10:29:56 +00:00
|
|
|
end
|
2016-03-16 22:44:33 +00:00
|
|
|
end
|