gitlab-org--gitlab-foss/spec/services/projects/create_service_spec.rb

151 lines
4 KiB
Ruby
Raw Normal View History

2013-01-18 13:21:13 -05:00
require 'spec_helper'
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
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
expect(project.labels).not_to be_empty
end
2015-09-03 11:44:58 -04:00
context 'user namespace' do
it do
project = create_project(user, opts)
2013-01-18 13:21:13 -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
end
2013-01-18 13:21:13 -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
before do
user.refresh_authorized_projects # Ensure cache is warm
end
it do
project = create_project(user, opts.merge!(namespace_id: group.id))
2013-01-18 13:21:13 -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
end
context 'error handling' do
it 'handles invalid options' do
opts.merge!({ default_branch: 'master' } )
expect(create_project(user, opts)).to eq(nil)
end
end
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)
expect(File.exist?(path)).to be_truthy
end
end
context 'wiki_enabled false does not create wiki repository directory' do
it do
opts.merge!(wiki_enabled: false)
project = create_project(user, opts)
path = ProjectWiki.new(project, user).send(:path_to_repo)
expect(File.exist?(path)).to be_falsey
end
end
end
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
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::DISABLED)
end
it { is_expected.to be_falsey }
end
context 'global builds_enabled true does enable CI by default' do
it { is_expected.to be_truthy }
end
end
context 'restricted visibility level' do
before do
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
opts.merge!(
visibility_level: Gitlab::VisibilityLevel.options['Public']
)
end
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
it 'allows a restricted visibility level for admins' do
admin = create(:admin)
project = create_project(admin, opts)
expect(project.errors.any?).to be(false)
expect(project.saved?).to be(true)
end
end
context 'repository creation' do
it 'synchronously creates the repository' do
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
context 'when there is an active service template' do
before do
create(:service, project: nil, template: true, active: true)
end
it 'creates a service from this template' do
project = create_project(user, opts)
expect(project.services.count).to eq 1
end
2013-01-18 13:21:13 -05:00
end
def create_project(user, opts)
Projects::CreateService.new(user, opts).execute
2013-01-18 13:21:13 -05:00
end
end