2013-01-18 13:21:13 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
describe Projects::CreateService, '#execute', services: true do
|
|
|
|
let(:user) { create :user }
|
|
|
|
let(:opts) do
|
|
|
|
{
|
|
|
|
name: "GitLab",
|
|
|
|
namespace: user.namespace
|
|
|
|
}
|
|
|
|
end
|
2013-01-18 13:21:13 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
it 'creates labels on Project creation if there are templates' do
|
|
|
|
Label.create(title: "bug", template: true)
|
|
|
|
project = create_project(user, opts)
|
2015-09-03 11:44:58 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
expect(project.labels).not_to be_empty
|
|
|
|
end
|
2015-09-03 11:44:58 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'user namespace' do
|
|
|
|
it do
|
|
|
|
project = create_project(user, opts)
|
2013-01-18 13:21:13 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
expect(project).to be_valid
|
|
|
|
expect(project.owner).to eq(user)
|
|
|
|
expect(project.team.masters).to include(user)
|
|
|
|
expect(project.namespace).to eq(user.namespace)
|
2013-01-18 13:21:13 -05:00
|
|
|
end
|
2016-11-20 03:42:58 -05:00
|
|
|
end
|
2013-01-18 13:21:13 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'group namespace' do
|
|
|
|
let(:group) do
|
|
|
|
create(:group).tap do |group|
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
|
|
|
end
|
2013-09-26 07:52:17 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
before do
|
|
|
|
user.refresh_authorized_projects # Ensure cache is warm
|
|
|
|
end
|
2016-10-11 08:25:17 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
it do
|
|
|
|
project = create_project(user, opts.merge!(namespace_id: group.id))
|
2013-01-18 13:21:13 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
expect(project).to be_valid
|
|
|
|
expect(project.owner).to eq(group)
|
|
|
|
expect(project.namespace).to eq(group)
|
|
|
|
expect(user.authorized_projects).to include(project)
|
2013-01-18 13:21:13 -05:00
|
|
|
end
|
2016-11-20 03:42:58 -05:00
|
|
|
end
|
2013-09-09 01:45:30 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'error handling' do
|
|
|
|
it 'handles invalid options' do
|
2017-02-21 18:50:22 -05:00
|
|
|
opts[:default_branch] = 'master'
|
2016-11-20 03:42:58 -05:00
|
|
|
expect(create_project(user, opts)).to eq(nil)
|
2015-12-09 00:49:24 -05:00
|
|
|
end
|
2016-11-20 03:42:58 -05:00
|
|
|
end
|
2015-12-09 00:49:24 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'wiki_enabled creates repository directory' do
|
|
|
|
context 'wiki_enabled true creates wiki repository directory' do
|
|
|
|
it do
|
|
|
|
project = create_project(user, opts)
|
|
|
|
path = ProjectWiki.new(project, user).send(:path_to_repo)
|
2014-03-14 06:53:05 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
expect(File.exist?(path)).to be_truthy
|
2014-03-14 06:53:05 -04:00
|
|
|
end
|
2016-11-20 03:42:58 -05:00
|
|
|
end
|
2014-03-14 06:53:05 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'wiki_enabled false does not create wiki repository directory' do
|
|
|
|
it do
|
2017-02-21 18:50:22 -05:00
|
|
|
opts[:wiki_enabled] = false
|
2016-11-20 03:42:58 -05:00
|
|
|
project = create_project(user, opts)
|
|
|
|
path = ProjectWiki.new(project, user).send(:path_to_repo)
|
2014-03-14 06:53:05 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
expect(File.exist?(path)).to be_falsey
|
2014-03-14 06:53:05 -04:00
|
|
|
end
|
|
|
|
end
|
2016-11-20 03:42:58 -05:00
|
|
|
end
|
2015-03-07 13:23:43 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'builds_enabled global setting' do
|
|
|
|
let(:project) { create_project(user, opts) }
|
2015-11-09 10:48:03 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
subject { project.builds_enabled? }
|
2015-11-09 10:48:03 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'global builds_enabled false does not enable CI by default' do
|
|
|
|
before do
|
|
|
|
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::DISABLED)
|
2015-11-09 10:48:03 -05:00
|
|
|
end
|
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
2015-11-09 10:48:03 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'global builds_enabled true does enable CI by default' do
|
|
|
|
it { is_expected.to be_truthy }
|
2015-11-09 10:48:03 -05:00
|
|
|
end
|
2016-11-20 03:42:58 -05:00
|
|
|
end
|
2015-11-09 10:48:03 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'restricted visibility level' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
|
2015-03-07 13:23:43 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
opts.merge!(
|
|
|
|
visibility_level: Gitlab::VisibilityLevel.options['Public']
|
|
|
|
)
|
|
|
|
end
|
2015-03-07 13:23:43 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
it 'does not allow a restricted visibility level for non-admins' do
|
|
|
|
project = create_project(user, opts)
|
|
|
|
expect(project).to respond_to(:errors)
|
|
|
|
expect(project.errors.messages).to have_key(:visibility_level)
|
|
|
|
expect(project.errors.messages[:visibility_level].first).to(
|
|
|
|
match('restricted by your GitLab administrator')
|
|
|
|
)
|
|
|
|
end
|
2015-03-07 13:23:43 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
it 'allows a restricted visibility level for admins' do
|
|
|
|
admin = create(:admin)
|
|
|
|
project = create_project(admin, opts)
|
2015-07-25 16:42:28 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
expect(project.errors.any?).to be(false)
|
|
|
|
expect(project.saved?).to be(true)
|
2015-03-07 13:23:43 -05:00
|
|
|
end
|
2016-11-20 03:42:58 -05:00
|
|
|
end
|
2015-09-01 03:56:40 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'repository creation' do
|
|
|
|
it 'synchronously creates the repository' do
|
|
|
|
expect_any_instance_of(Project).to receive(:create_repository)
|
2015-09-01 03:56:40 -04:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
project = create_project(user, opts)
|
|
|
|
expect(project).to be_valid
|
|
|
|
expect(project.owner).to eq(user)
|
|
|
|
expect(project.namespace).to eq(user.namespace)
|
2015-09-01 03:56:40 -04:00
|
|
|
end
|
2016-11-20 03:42:58 -05:00
|
|
|
end
|
2016-11-16 06:46:07 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
context 'when there is an active service template' do
|
|
|
|
before do
|
|
|
|
create(:service, project: nil, template: true, active: true)
|
|
|
|
end
|
2016-11-16 06:46:07 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
it 'creates a service from this template' do
|
|
|
|
project = create_project(user, opts)
|
2016-11-16 06:46:07 -05:00
|
|
|
|
2016-11-20 03:42:58 -05:00
|
|
|
expect(project.services.count).to eq 1
|
2016-11-16 06:46:07 -05:00
|
|
|
end
|
2013-01-18 13:21:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_project(user, opts)
|
2014-01-16 13:29:18 -05:00
|
|
|
Projects::CreateService.new(user, opts).execute
|
2013-01-18 13:21:13 -05:00
|
|
|
end
|
|
|
|
end
|