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
|
# frozen_string_literal: true
RSpec.shared_examples 'clone quick action' do
context 'clone the issue to another project' do
let(:target_project) { create(:project, :public) }
context 'when no target is given' do
it 'clones the issue in the current project' do
add_note("/clone")
expect(page).to have_content "Cloned this issue to #{project.full_path}."
expect(issue.reload).to be_open
visit project_issue_path(project, issue)
expect(page).to have_content 'Issues 2'
end
end
context 'when the project is valid' do
before do
target_project.add_maintainer(user)
end
it 'clones the issue' do
add_note("/clone #{target_project.full_path}")
expect(page).to have_content "Cloned this issue to #{target_project.full_path}."
expect(issue.reload).to be_open
visit project_issue_path(target_project, issue)
expect(page).to have_content 'Issues 1'
end
context 'when cloning with notes', :aggregate_failures do
it 'clones the issue with all notes' do
add_note("Some random note")
add_note("Another note")
add_note("/clone --with_notes #{target_project.full_path}")
expect(page).to have_content "Cloned this issue to #{target_project.full_path}."
expect(issue.reload).to be_open
visit project_issue_path(target_project, issue)
expect(page).to have_content 'Issues 1'
expect(page).to have_content 'Some random note'
expect(page).to have_content 'Another note'
end
it 'returns an error if the params are malformed' do
# Note that this is missing one `-`
add_note("/clone -with_notes #{target_project.full_path}")
wait_for_requests
expect(page).to have_content 'Failed to clone this issue: wrong parameters.'
expect(issue.reload).to be_open
end
end
end
context 'when the project is valid but the user not authorized' do
let(:project_unauthorized) { create(:project, :public) }
it 'does not clone the issue' do
add_note("/clone #{project_unauthorized.full_path}")
wait_for_requests
expect(page).to have_content "Cloned this issue to #{project_unauthorized.full_path}."
expect(issue.reload).to be_open
visit project_issue_path(target_project, issue)
expect(page).not_to have_content 'Issues 1'
end
end
context 'when the project is invalid' do
it 'does not clone the issue' do
add_note("/clone not/valid")
wait_for_requests
expect(page).to have_content "Failed to clone this issue because target project doesn't exist."
expect(issue.reload).to be_open
end
end
context 'when the user issues multiple commands' do
let(:milestone) { create(:milestone, title: '1.0', project: project) }
let(:bug) { create(:label, project: project, title: 'bug') }
let(:wontfix) { create(:label, project: project, title: 'wontfix') }
let!(:target_milestone) { create(:milestone, title: '1.0', project: target_project) }
before do
target_project.add_maintainer(user)
end
shared_examples 'applies the commands to issues in both projects, target and source' do
it "applies quick actions" do
expect(page).to have_content "Cloned this issue to #{target_project.full_path}."
expect(issue.reload).to be_open
visit project_issue_path(target_project, issue)
expect(page).to have_content 'bug'
expect(page).to have_content 'wontfix'
expect(page).to have_content '1.0'
visit project_issue_path(project, issue)
expect(page).to have_content 'bug'
expect(page).to have_content 'wontfix'
expect(page).to have_content '1.0'
end
end
context 'applies multiple commands with clone command in the end' do
before do
add_note("/label ~#{bug.title} ~#{wontfix.title}\n\n/milestone %\"#{milestone.title}\"\n\n/clone #{target_project.full_path}")
end
it_behaves_like 'applies the commands to issues in both projects, target and source'
end
context 'applies multiple commands with clone command in the begining' do
before do
add_note("/clone #{target_project.full_path}\n\n/label ~#{bug.title} ~#{wontfix.title}\n\n/milestone %\"#{milestone.title}\"")
end
it_behaves_like 'applies the commands to issues in both projects, target and source'
end
end
context 'when editing comments' do
let(:target_project) { create(:project, :public) }
before do
target_project.add_maintainer(user)
sign_in(user)
visit project_issue_path(project, issue)
wait_for_all_requests
end
it 'clones the issue after quickcommand note was updated' do
# misspelled quick action
add_note("test note.\n/cloe #{target_project.full_path}")
expect(issue.reload).not_to be_closed
edit_note("/cloe #{target_project.full_path}", "test note.\n/clone #{target_project.full_path}")
wait_for_all_requests
expect(page).to have_content 'test note.'
expect(issue.reload).to be_open
visit project_issue_path(target_project, issue)
wait_for_all_requests
expect(page).to have_content 'Issues 1'
end
it 'deletes the note if it was updated to just contain a command' do
# missspelled quick action
add_note("test note.\n/cloe #{target_project.full_path}")
expect(page).not_to have_content 'Commands applied'
edit_note("/cloe #{target_project.full_path}", "/clone #{target_project.full_path}")
wait_for_all_requests
expect(page).not_to have_content "/clone #{target_project.full_path}"
expect(issue.reload).to be_open
visit project_issue_path(target_project, issue)
wait_for_all_requests
expect(page).to have_content 'Issues 1'
end
end
end
end
|