1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
require 'spec_helper'
describe Projects::CreateService, services: true do
describe :create_by_user do
before do
@user = create :user
@opts = {
name: "GitLab",
namespace: @user.namespace
}
end
it 'creates services on Project creation' do
project = create_project(@user, @opts)
project.reload
expect(project.services).not_to be_empty
end
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
context 'user namespace' do
before do
@project = create_project(@user, @opts)
end
it { expect(@project).to be_valid }
it { expect(@project.owner).to eq(@user) }
it { expect(@project.team.masters).to include(@user) }
it { expect(@project.namespace).to eq(@user.namespace) }
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
it { expect(@project).to be_valid }
it { expect(@project.owner).to eq(@group) }
it { expect(@project.namespace).to eq(@group) }
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
before do
@project = create_project(@user, @opts)
@path = ProjectWiki.new(@project, @user).send(:path_to_repo)
end
it { expect(File.exist?(@path)).to be_truthy }
end
context 'wiki_enabled false does not create wiki repository directory' do
before do
@opts.merge!( { project_feature_attributes: { wiki_access_level: ProjectFeature::DISABLED } })
@project = create_project(@user, @opts)
@path = ProjectWiki.new(@project, @user).send(:path_to_repo)
end
it { expect(File.exist?(@path)).to be_falsey }
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
before do
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::ENABLED)
end
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
end
def create_project(user, opts)
Projects::CreateService.new(user, opts).execute
end
end
|