2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe Projects::CreateService, services: true do
|
2014-09-02 18:07:02 +05:30
|
|
|
describe :create_by_user do
|
|
|
|
before do
|
|
|
|
@user = create :user
|
|
|
|
@opts = {
|
|
|
|
name: "GitLab",
|
|
|
|
namespace: @user.namespace
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
it 'creates services on Project creation' do
|
|
|
|
project = create_project(@user, @opts)
|
|
|
|
project.reload
|
|
|
|
|
|
|
|
expect(project.services).not_to be_empty
|
|
|
|
end
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
it 'creates labels on Project creation if there are templates' do
|
|
|
|
Label.create(title: "bug", template: true)
|
|
|
|
project = create_project(@user, @opts)
|
|
|
|
project.reload
|
|
|
|
|
|
|
|
expect(project.labels).not_to be_empty
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
context 'user namespace' do
|
|
|
|
before do
|
|
|
|
@project = create_project(@user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@project).to be_valid }
|
|
|
|
it { expect(@project.owner).to eq(@user) }
|
2016-01-29 22:53:50 +05:30
|
|
|
it { expect(@project.team.masters).to include(@user) }
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@project.namespace).to eq(@user.namespace) }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'group namespace' do
|
|
|
|
before do
|
|
|
|
@group = create :group
|
|
|
|
@group.add_owner(@user)
|
|
|
|
|
|
|
|
@opts.merge!(namespace_id: @group.id)
|
|
|
|
@project = create_project(@user, @opts)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(@project).to be_valid }
|
|
|
|
it { expect(@project.owner).to eq(@group) }
|
|
|
|
it { expect(@project.namespace).to eq(@group) }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
context 'error handling' do
|
|
|
|
it 'handles invalid options' do
|
|
|
|
@opts.merge!({ default_branch: 'master' } )
|
|
|
|
expect(create_project(@user, @opts)).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
context 'wiki_enabled creates repository directory' do
|
|
|
|
context 'wiki_enabled true creates wiki repository directory' do
|
|
|
|
before do
|
|
|
|
@project = create_project(@user, @opts)
|
|
|
|
@path = ProjectWiki.new(@project, @user).send(:path_to_repo)
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it { expect(File.exist?(@path)).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'wiki_enabled false does not create wiki repository directory' do
|
|
|
|
before do
|
2016-11-24 13:41:30 +05:30
|
|
|
@opts.merge!(wiki_enabled: false)
|
2014-09-02 18:07:02 +05:30
|
|
|
@project = create_project(@user, @opts)
|
|
|
|
@path = ProjectWiki.new(@project, @user).send(:path_to_repo)
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
it { expect(File.exist?(@path)).to be_falsey }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
context 'builds_enabled global setting' do
|
|
|
|
let(:project) { create_project(@user, @opts) }
|
|
|
|
|
|
|
|
subject { project.builds_enabled? }
|
|
|
|
|
|
|
|
context 'global builds_enabled false does not enable CI by default' do
|
|
|
|
before do
|
2016-09-29 09:46:39 +05:30
|
|
|
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::DISABLED)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'global builds_enabled true does enable CI by default' do
|
|
|
|
before do
|
2016-09-29 09:46:39 +05:30
|
|
|
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::ENABLED)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
context 'restricted visibility level' do
|
|
|
|
before do
|
2015-09-11 14:41:01 +05:30
|
|
|
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
@opts.merge!(
|
|
|
|
visibility_level: Gitlab::VisibilityLevel.options['Public']
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not allow a restricted visibility level for non-admins' do
|
2015-04-26 12:48:37 +05:30
|
|
|
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
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'allows a restricted visibility level for admins' do
|
2015-09-11 14:41:01 +05:30
|
|
|
admin = create(:admin)
|
|
|
|
project = create_project(admin, @opts)
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(project.errors.any?).to be(false)
|
|
|
|
expect(project.saved?).to be(true)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
|
|
|
|
context 'repository creation' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'synchronously creates the repository' do
|
2015-09-25 12:07:36 +05:30
|
|
|
expect_any_instance_of(Project).to receive(:create_repository)
|
|
|
|
|
|
|
|
project = create_project(@user, @opts)
|
|
|
|
expect(project).to be_valid
|
|
|
|
expect(project.owner).to eq(@user)
|
|
|
|
expect(project.namespace).to eq(@user.namespace)
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create_project(user, opts)
|
|
|
|
Projects::CreateService.new(user, opts).execute
|
|
|
|
end
|
|
|
|
end
|