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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Project fork' do
include ProjectForksHelper
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository, description: 'some description') }
before do
sign_in(user)
end
shared_examples 'fork button on project page' do
it 'allows user to fork project from the project page' do
visit project_path(project)
expect(page).not_to have_css('a.disabled', text: 'Fork')
end
context 'user has exceeded personal project limit' do
before do
user.update!(projects_limit: 0)
end
it 'disables fork button on project page' do
visit project_path(project)
expect(page).to have_css('a.disabled', text: 'Fork')
end
end
end
shared_examples 'create fork page' do |fork_page_text|
before do
project.project_feature.update_attribute(
:forking_access_level, forking_access_level)
end
context 'forking is enabled' do
let(:forking_access_level) { ProjectFeature::ENABLED }
it 'enables fork button' do
visit project_path(project)
expect(page).to have_css('a', text: 'Fork')
expect(page).not_to have_css('a.disabled', text: 'Select')
end
it 'renders new project fork page' do
visit new_project_fork_path(project)
expect(page.status_code).to eq(200)
expect(page).to have_text(fork_page_text)
end
end
context 'forking is disabled' do
let(:forking_access_level) { ProjectFeature::DISABLED }
it 'render a disabled fork button' do
visit project_path(project)
expect(page).to have_css('a.disabled', text: 'Fork')
expect(page).to have_css('a.count', text: '0')
end
it 'does not render new project fork page' do
visit new_project_fork_path(project)
expect(page.status_code).to eq(404)
end
end
context 'forking is private' do
let(:forking_access_level) { ProjectFeature::PRIVATE }
before do
project.update!(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
end
context 'user is not a team member' do
it 'render a disabled fork button' do
visit project_path(project)
expect(page).to have_css('a.disabled', text: 'Fork')
expect(page).to have_css('a.count', text: '0')
end
it 'does not render new project fork page' do
visit new_project_fork_path(project)
expect(page.status_code).to eq(404)
end
end
context 'user is a team member' do
before do
project.add_developer(user)
end
it 'enables fork button' do
visit project_path(project)
expect(page).to have_css('a', text: 'Fork')
expect(page).to have_css('a.count', text: '0')
expect(page).not_to have_css('a.disabled', text: 'Fork')
end
it 'renders new project fork page' do
visit new_project_fork_path(project)
expect(page.status_code).to eq(200)
expect(page).to have_text(fork_page_text)
end
end
end
end
it_behaves_like 'fork button on project page'
it_behaves_like 'create fork page', 'Fork project'
context 'fork form', :js do
let(:group) { create(:group) }
let(:user) { create(:group_member, :maintainer, user: create(:user), group: group ).user }
def submit_form
select(group.name)
click_button 'Fork project'
end
it 'forks the project', :sidekiq_might_not_need_inline do
visit new_project_fork_path(project)
submit_form
expect(page).to have_content 'Forked from'
end
it 'shows the new forked project on the forks page' do
visit new_project_fork_path(project)
submit_form
wait_for_requests
visit project_forks_path(project)
page.within('.js-projects-list-holder') do
expect(page).to have_content("#{group.name} / #{project.name}")
end
end
it 'shows the filled in info forked project on the forks page' do
fork_name = 'some-name'
visit new_project_fork_path(project)
fill_in('fork-name', with: fork_name, fill_options: { clear: :backspace })
fill_in('fork-slug', with: fork_name, fill_options: { clear: :backspace })
submit_form
wait_for_requests
visit project_forks_path(project)
page.within('.js-projects-list-holder') do
expect(page).to have_content("#{group.name} / #{fork_name}")
end
end
end
context 'with fork_project_form feature flag disabled' do
before do
stub_feature_flags(fork_project_form: false)
sign_in(user)
end
it_behaves_like 'fork button on project page'
context 'user has exceeded personal project limit' do
before do
user.update!(projects_limit: 0)
end
context 'with a group to fork to' do
let!(:group) { create(:group).tap { |group| group.add_owner(user) } }
it 'allows user to fork only to the group on fork page', :js do
visit new_project_fork_path(project)
to_personal_namespace = find('[data-qa-selector=fork_namespace_button].disabled') # rubocop:disable QA/SelectorUsage
to_group = find(".fork-groups button[data-qa-name=#{group.name}]") # rubocop:disable QA/SelectorUsage
expect(to_personal_namespace).not_to be_nil
expect(to_group).not_to be_disabled
end
end
end
it_behaves_like 'create fork page', ' Select a namespace to fork the project '
it 'forks the project', :sidekiq_might_not_need_inline do
visit project_path(project)
click_link 'Fork'
page.within '.fork-thumbnail-container' do
click_link 'Select'
end
expect(page).to have_content 'Forked from'
visit project_path(project)
expect(page).to have_content(/new merge request/i)
page.within '.nav-sidebar' do
first(:link, 'Merge requests').click
end
expect(page).to have_content(/new merge request/i)
page.within '#content-body' do
click_link('New merge request')
end
expect(current_path).to have_content(/#{user.namespace.path}/i)
end
it 'shows avatars when Gravatar is disabled' do
stub_application_setting(gravatar_enabled: false)
visit project_path(project)
click_link 'Fork'
page.within('.fork-thumbnail-container') do
expect(page).to have_css('span.identicon')
end
end
it 'shows the forked project on the list' do
visit project_path(project)
click_link 'Fork'
page.within '.fork-thumbnail-container' do
click_link 'Select'
end
visit project_forks_path(project)
forked_project = user.fork_of(project.reload)
page.within('.js-projects-list-holder') do
expect(page).to have_content("#{forked_project.namespace.human_name} / #{forked_project.name}")
end
forked_project.update!(path: 'test-crappy-path')
visit project_forks_path(project)
page.within('.js-projects-list-holder') do
expect(page).to have_content("#{forked_project.namespace.human_name} / #{forked_project.name}")
end
end
context 'when the project is private' do
let(:project) { create(:project, :repository) }
let(:another_user) { create(:user, name: 'Mike') }
before do
project.add_reporter(user)
project.add_reporter(another_user)
end
it 'renders private forks of the project' do
visit project_path(project)
another_project_fork = Projects::ForkService.new(project, another_user).execute
click_link 'Fork'
page.within '.fork-thumbnail-container' do
click_link 'Select'
end
visit project_forks_path(project)
page.within('.js-projects-list-holder') do
user_project_fork = user.fork_of(project.reload)
expect(page).to have_content("#{user_project_fork.namespace.human_name} / #{user_project_fork.name}")
end
expect(page).not_to have_content("#{another_project_fork.namespace.human_name} / #{another_project_fork.name}")
end
end
context 'when the user already forked the project' do
before do
create(:project, :repository, name: project.name, namespace: user.namespace)
end
it 'renders error' do
visit project_path(project)
click_link 'Fork'
page.within '.fork-thumbnail-container' do
click_link 'Select'
end
expect(page).to have_content "Name has already been taken"
end
end
context 'maintainer in group' do
let(:group) { create(:group) }
before do
group.add_maintainer(user)
end
it 'allows user to fork project to group or to user namespace', :js do
visit project_path(project)
wait_for_requests
expect(page).not_to have_css('a.disabled', text: 'Fork')
click_link 'Fork'
expect(page).to have_css('.fork-thumbnail')
expect(page).to have_css('.group-row')
expect(page).not_to have_css('.fork-thumbnail.disabled')
end
it 'allows user to fork project to group and not user when exceeded project limit', :js do
user.projects_limit = 0
user.save!
visit project_path(project)
wait_for_requests
expect(page).not_to have_css('a.disabled', text: 'Fork')
click_link 'Fork'
expect(page).to have_css('.fork-thumbnail.disabled')
expect(page).to have_css('.group-row')
end
it 'links to the fork if the project was already forked within that namespace', :sidekiq_might_not_need_inline, :js do
forked_project = fork_project(project, user, namespace: group, repository: true)
visit new_project_fork_path(project)
wait_for_requests
expect(page).to have_css('.group-row a.btn', text: 'Go to fork')
click_link 'Go to fork'
expect(current_path).to eq(project_path(forked_project))
end
end
end
end
|