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
|
require 'rails_helper'
describe 'Merge request > User uses quick actions', :js do
include Spec::Support::Helpers::Features::NotesHelpers
let(:project) { create(:project, :public, :repository) }
let(:user) { project.creator }
let(:guest) { create(:user) }
let(:merge_request) { create(:merge_request, source_project: project) }
let!(:milestone) { create(:milestone, project: project, title: 'ASAP') }
context "issuable common quick actions" do
let!(:new_url_opts) { { merge_request: { source_branch: 'feature', target_branch: 'master' } } }
let(:maintainer) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let!(:label_bug) { create(:label, project: project, title: 'bug') }
let!(:label_feature) { create(:label, project: project, title: 'feature') }
let!(:milestone) { create(:milestone, project: project, title: 'ASAP') }
let(:issuable) { create(:merge_request, source_project: project) }
let(:source_issuable) { create(:issue, project: project, milestone: milestone, labels: [label_bug, label_feature])}
it_behaves_like 'assign quick action', :merge_request
it_behaves_like 'unassign quick action', :merge_request
it_behaves_like 'close quick action', :merge_request
it_behaves_like 'reopen quick action', :merge_request
it_behaves_like 'title quick action', :merge_request
it_behaves_like 'todo quick action', :merge_request
it_behaves_like 'done quick action', :merge_request
it_behaves_like 'subscribe quick action', :merge_request
it_behaves_like 'unsubscribe quick action', :merge_request
it_behaves_like 'lock quick action', :merge_request
it_behaves_like 'unlock quick action', :merge_request
it_behaves_like 'milestone quick action', :merge_request
it_behaves_like 'remove_milestone quick action', :merge_request
it_behaves_like 'label quick action', :merge_request
it_behaves_like 'unlabel quick action', :merge_request
it_behaves_like 'relabel quick action', :merge_request
it_behaves_like 'award quick action', :merge_request
it_behaves_like 'estimate quick action', :merge_request
it_behaves_like 'remove_estimate quick action', :merge_request
it_behaves_like 'spend quick action', :merge_request
it_behaves_like 'remove_time_spent quick action', :merge_request
it_behaves_like 'shrug quick action', :merge_request
it_behaves_like 'tableflip quick action', :merge_request
it_behaves_like 'copy_metadata quick action', :merge_request
it_behaves_like 'issuable time tracker', :merge_request
end
describe 'merge-request-only commands' do
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:merge_request) { create(:merge_request, source_project: project) }
let!(:milestone) { create(:milestone, project: project, title: 'ASAP') }
before do
project.add_maintainer(user)
end
describe 'toggling the WIP prefix in the title from note' do
context 'when the current user can toggle the WIP prefix' do
before do
sign_in(user)
visit project_merge_request_path(project, merge_request)
wait_for_requests
end
it 'adds the WIP: prefix to the title' do
add_note("/wip")
expect(page).not_to have_content '/wip'
expect(page).to have_content 'Commands applied'
expect(merge_request.reload.work_in_progress?).to eq true
end
it 'removes the WIP: prefix from the title' do
merge_request.title = merge_request.wip_title
merge_request.save
add_note("/wip")
expect(page).not_to have_content '/wip'
expect(page).to have_content 'Commands applied'
expect(merge_request.reload.work_in_progress?).to eq false
end
end
context 'when the current user cannot toggle the WIP prefix' do
before do
project.add_guest(guest)
sign_in(guest)
visit project_merge_request_path(project, merge_request)
end
it 'does not change the WIP prefix' do
add_note("/wip")
expect(page).not_to have_content '/wip'
expect(page).not_to have_content 'Commands applied'
expect(merge_request.reload.work_in_progress?).to eq false
end
end
end
describe 'merging the MR from the note' do
context 'when the current user can merge the MR' do
before do
sign_in(user)
visit project_merge_request_path(project, merge_request)
end
it 'merges the MR' do
add_note("/merge")
expect(page).to have_content 'Commands applied'
expect(merge_request.reload).to be_merged
end
end
context 'when the head diff changes in the meanwhile' do
before do
merge_request.source_branch = 'another_branch'
merge_request.save
sign_in(user)
visit project_merge_request_path(project, merge_request)
end
it 'does not merge the MR' do
add_note("/merge")
expect(page).not_to have_content 'Your commands have been executed!'
expect(merge_request.reload).not_to be_merged
end
end
context 'when the current user cannot merge the MR' do
before do
project.add_guest(guest)
sign_in(guest)
visit project_merge_request_path(project, merge_request)
end
it 'does not merge the MR' do
add_note("/merge")
expect(page).not_to have_content 'Your commands have been executed!'
expect(merge_request.reload).not_to be_merged
end
end
end
describe 'adding a due date from note' do
before do
sign_in(user)
visit project_merge_request_path(project, merge_request)
end
it_behaves_like 'due quick action not available'
end
describe 'removing a due date from note' do
before do
sign_in(user)
visit project_merge_request_path(project, merge_request)
end
it_behaves_like 'remove_due_date action not available'
end
describe '/target_branch command in merge request' do
let(:another_project) { create(:project, :public, :repository) }
let(:new_url_opts) { { merge_request: { source_branch: 'feature' } } }
before do
another_project.add_maintainer(user)
sign_in(user)
end
it 'changes target_branch in new merge_request' do
visit project_new_merge_request_path(another_project, new_url_opts)
fill_in "merge_request_title", with: 'My brand new feature'
fill_in "merge_request_description", with: "le feature \n/target_branch fix\nFeature description:"
click_button "Submit merge request"
merge_request = another_project.merge_requests.first
expect(merge_request.description).to eq "le feature \nFeature description:"
expect(merge_request.target_branch).to eq 'fix'
end
it 'does not change target branch when merge request is edited' do
new_merge_request = create(:merge_request, source_project: another_project)
visit edit_project_merge_request_path(another_project, new_merge_request)
fill_in "merge_request_description", with: "Want to update target branch\n/target_branch fix\n"
click_button "Save changes"
new_merge_request = another_project.merge_requests.first
expect(new_merge_request.description).to include('/target_branch')
expect(new_merge_request.target_branch).not_to eq('fix')
end
end
describe '/target_branch command from note' do
context 'when the current user can change target branch' do
before do
sign_in(user)
visit project_merge_request_path(project, merge_request)
end
it 'changes target branch from a note' do
add_note("message start \n/target_branch merge-test\n message end.")
wait_for_requests
expect(page).not_to have_content('/target_branch')
expect(page).to have_content('message start')
expect(page).to have_content('message end.')
expect(merge_request.reload.target_branch).to eq 'merge-test'
end
it 'does not fail when target branch does not exists' do
add_note('/target_branch totally_not_existing_branch')
expect(page).not_to have_content('/target_branch')
expect(merge_request.target_branch).to eq 'feature'
end
end
context 'when current user can not change target branch' do
before do
project.add_guest(guest)
sign_in(guest)
visit project_merge_request_path(project, merge_request)
end
it 'does not change target branch' do
add_note('/target_branch merge-test')
expect(page).not_to have_content '/target_branch merge-test'
expect(merge_request.target_branch).to eq 'feature'
end
end
end
end
end
|