@@ -1,881 +1,914 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base |
|
21 | 21 | fixtures :projects, |
|
22 | 22 | :users, |
|
23 | 23 | :roles, |
|
24 | 24 | :members, |
|
25 | 25 | :member_roles, |
|
26 | 26 | :issues, |
|
27 | 27 | :issue_statuses, |
|
28 | 28 | :issue_relations, |
|
29 | 29 | :versions, |
|
30 | 30 | :trackers, |
|
31 | 31 | :projects_trackers, |
|
32 | 32 | :issue_categories, |
|
33 | 33 | :enabled_modules, |
|
34 | 34 | :enumerations, |
|
35 | 35 | :attachments, |
|
36 | 36 | :workflows, |
|
37 | 37 | :custom_fields, |
|
38 | 38 | :custom_values, |
|
39 | 39 | :custom_fields_projects, |
|
40 | 40 | :custom_fields_trackers, |
|
41 | 41 | :time_entries, |
|
42 | 42 | :journals, |
|
43 | 43 | :journal_details, |
|
44 | 44 | :queries, |
|
45 | 45 | :attachments |
|
46 | 46 | |
|
47 | 47 | test "GET /issues.xml should contain metadata" do |
|
48 | 48 | get '/issues.xml' |
|
49 | 49 | assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]', |
|
50 | 50 | assigns(:issue_count).to_s |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | test "GET /issues.xml with nometa param should not contain metadata" do |
|
54 | 54 | get '/issues.xml?nometa=1' |
|
55 | 55 | assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])' |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | test "GET /issues.xml with nometa header should not contain metadata" do |
|
59 | 59 | get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'} |
|
60 | 60 | assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])' |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | test "GET /issues.xml with offset and limit" do |
|
64 | 64 | get '/issues.xml?offset=2&limit=3' |
|
65 | 65 | |
|
66 | 66 | assert_equal 3, assigns(:limit) |
|
67 | 67 | assert_equal 2, assigns(:offset) |
|
68 | 68 | assert_select 'issues issue', 3 |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | test "GET /issues.xml with relations" do |
|
72 | 72 | get '/issues.xml?include=relations' |
|
73 | 73 | |
|
74 | 74 | assert_response :success |
|
75 | 75 | assert_equal 'application/xml', @response.content_type |
|
76 | 76 | |
|
77 | 77 | assert_select 'issue id', :text => '3' do |
|
78 | 78 | assert_select '~ relations relation', 1 |
|
79 | 79 | assert_select '~ relations relation[id="2"][issue_id="2"][issue_to_id="3"][relation_type=relates]' |
|
80 | 80 | end |
|
81 | 81 | |
|
82 | 82 | assert_select 'issue id', :text => '1' do |
|
83 | 83 | assert_select '~ relations' |
|
84 | 84 | assert_select '~ relations relation', 0 |
|
85 | 85 | end |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | test "GET /issues.xml with invalid query params" do |
|
89 | 89 | get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}} |
|
90 | 90 | |
|
91 | 91 | assert_response :unprocessable_entity |
|
92 | 92 | assert_equal 'application/xml', @response.content_type |
|
93 | 93 | assert_select 'errors error', :text => "Start date cannot be blank" |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | test "GET /issues.xml with custom field filter" do |
|
97 | 97 | get '/issues.xml', |
|
98 | 98 | {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}} |
|
99 | 99 | |
|
100 | 100 | expected_ids = Issue.visible. |
|
101 | 101 | joins(:custom_values). |
|
102 | 102 | where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id) |
|
103 | 103 | assert expected_ids.any? |
|
104 | 104 | |
|
105 | 105 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| |
|
106 | 106 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } |
|
107 | 107 | end |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | test "GET /issues.xml with custom field filter (shorthand method)" do |
|
111 | 111 | get '/issues.xml', {:cf_1 => 'MySQL'} |
|
112 | 112 | |
|
113 | 113 | expected_ids = Issue.visible. |
|
114 | 114 | joins(:custom_values). |
|
115 | 115 | where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id) |
|
116 | 116 | assert expected_ids.any? |
|
117 | 117 | |
|
118 | 118 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| |
|
119 | 119 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } |
|
120 | 120 | end |
|
121 | 121 | end |
|
122 | 122 | |
|
123 | 123 | def test_index_should_include_issue_attributes |
|
124 | 124 | get '/issues.xml' |
|
125 | 125 | assert_select 'issues>issue>is_private', :text => 'false' |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | def test_index_should_allow_timestamp_filtering |
|
129 | 129 | Issue.delete_all |
|
130 | 130 | Issue.generate!(:subject => '1').update_column(:updated_on, Time.parse("2014-01-02T10:25:00Z")) |
|
131 | 131 | Issue.generate!(:subject => '2').update_column(:updated_on, Time.parse("2014-01-02T12:13:00Z")) |
|
132 | 132 | |
|
133 | 133 | get '/issues.xml', |
|
134 | 134 | {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '<='}, |
|
135 | 135 | :v => {:updated_on => ['2014-01-02T12:00:00Z']}} |
|
136 | 136 | assert_select 'issues>issue', :count => 1 |
|
137 | 137 | assert_select 'issues>issue>subject', :text => '1' |
|
138 | 138 | |
|
139 | 139 | get '/issues.xml', |
|
140 | 140 | {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='}, |
|
141 | 141 | :v => {:updated_on => ['2014-01-02T12:00:00Z']}} |
|
142 | 142 | assert_select 'issues>issue', :count => 1 |
|
143 | 143 | assert_select 'issues>issue>subject', :text => '2' |
|
144 | 144 | |
|
145 | 145 | get '/issues.xml', |
|
146 | 146 | {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='}, |
|
147 | 147 | :v => {:updated_on => ['2014-01-02T08:00:00Z']}} |
|
148 | 148 | assert_select 'issues>issue', :count => 2 |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | test "GET /issues.xml with filter" do |
|
152 | 152 | get '/issues.xml?status_id=5' |
|
153 | 153 | |
|
154 | 154 | expected_ids = Issue.visible.where(:status_id => 5).map(&:id) |
|
155 | 155 | assert expected_ids.any? |
|
156 | 156 | |
|
157 | 157 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| |
|
158 | 158 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } |
|
159 | 159 | end |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | test "GET /issues.json with filter" do |
|
163 | 163 | get '/issues.json?status_id=5' |
|
164 | 164 | |
|
165 | 165 | json = ActiveSupport::JSON.decode(response.body) |
|
166 | 166 | status_ids_used = json['issues'].collect {|j| j['status']['id'] } |
|
167 | 167 | assert_equal 3, status_ids_used.length |
|
168 | 168 | assert status_ids_used.all? {|id| id == 5 } |
|
169 | 169 | end |
|
170 | 170 | |
|
171 | 171 | test "GET /issues/:id.xml with journals" do |
|
172 | 172 | Journal.find(2).update_attribute(:private_notes, true) |
|
173 | 173 | |
|
174 | 174 | get '/issues/1.xml?include=journals', {}, credentials('jsmith') |
|
175 | 175 | |
|
176 | 176 | assert_select 'issue journals[type=array]' do |
|
177 | 177 | assert_select 'journal[id="1"]' do |
|
178 | 178 | assert_select 'private_notes', :text => 'false' |
|
179 | 179 | assert_select 'details[type=array]' do |
|
180 | 180 | assert_select 'detail[name=status_id]' do |
|
181 | 181 | assert_select 'old_value', :text => '1' |
|
182 | 182 | assert_select 'new_value', :text => '2' |
|
183 | 183 | end |
|
184 | 184 | end |
|
185 | 185 | end |
|
186 | 186 | assert_select 'journal[id="2"]' do |
|
187 | 187 | assert_select 'private_notes', :text => 'true' |
|
188 | 188 | assert_select 'details[type=array]' |
|
189 | 189 | end |
|
190 | 190 | end |
|
191 | 191 | end |
|
192 | 192 | |
|
193 | 193 | test "GET /issues/:id.xml with journals should format timestamps in ISO 8601" do |
|
194 | 194 | get '/issues/1.xml?include=journals' |
|
195 | 195 | |
|
196 | 196 | iso_date = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/ |
|
197 | 197 | assert_select 'issue>created_on', :text => iso_date |
|
198 | 198 | assert_select 'issue>updated_on', :text => iso_date |
|
199 | 199 | assert_select 'issue journal>created_on', :text => iso_date |
|
200 | 200 | end |
|
201 | 201 | |
|
202 | 202 | test "GET /issues/:id.xml with custom fields" do |
|
203 | 203 | get '/issues/3.xml' |
|
204 | 204 | |
|
205 | 205 | assert_select 'issue custom_fields[type=array]' do |
|
206 | 206 | assert_select 'custom_field[id="1"]' do |
|
207 | 207 | assert_select 'value', :text => 'MySQL' |
|
208 | 208 | end |
|
209 | 209 | end |
|
210 | 210 | assert_nothing_raised do |
|
211 | 211 | Hash.from_xml(response.body).to_xml |
|
212 | 212 | end |
|
213 | 213 | end |
|
214 | 214 | |
|
215 | 215 | test "GET /issues/:id.xml with multi custom fields" do |
|
216 | 216 | field = CustomField.find(1) |
|
217 | 217 | field.update_attribute :multiple, true |
|
218 | 218 | issue = Issue.find(3) |
|
219 | 219 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
220 | 220 | issue.save! |
|
221 | 221 | |
|
222 | 222 | get '/issues/3.xml' |
|
223 | 223 | assert_response :success |
|
224 | 224 | |
|
225 | 225 | assert_select 'issue custom_fields[type=array]' do |
|
226 | 226 | assert_select 'custom_field[id="1"]' do |
|
227 | 227 | assert_select 'value[type=array] value', 2 |
|
228 | 228 | end |
|
229 | 229 | end |
|
230 | 230 | xml = Hash.from_xml(response.body) |
|
231 | 231 | custom_fields = xml['issue']['custom_fields'] |
|
232 | 232 | assert_kind_of Array, custom_fields |
|
233 | 233 | field = custom_fields.detect {|f| f['id'] == '1'} |
|
234 | 234 | assert_kind_of Hash, field |
|
235 | 235 | assert_equal ['MySQL', 'Oracle'], field['value'].sort |
|
236 | 236 | end |
|
237 | 237 | |
|
238 | 238 | test "GET /issues/:id.json with multi custom fields" do |
|
239 | 239 | field = CustomField.find(1) |
|
240 | 240 | field.update_attribute :multiple, true |
|
241 | 241 | issue = Issue.find(3) |
|
242 | 242 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
243 | 243 | issue.save! |
|
244 | 244 | |
|
245 | 245 | get '/issues/3.json' |
|
246 | 246 | assert_response :success |
|
247 | 247 | |
|
248 | 248 | json = ActiveSupport::JSON.decode(response.body) |
|
249 | 249 | custom_fields = json['issue']['custom_fields'] |
|
250 | 250 | assert_kind_of Array, custom_fields |
|
251 | 251 | field = custom_fields.detect {|f| f['id'] == 1} |
|
252 | 252 | assert_kind_of Hash, field |
|
253 | 253 | assert_equal ['MySQL', 'Oracle'], field['value'].sort |
|
254 | 254 | end |
|
255 | 255 | |
|
256 | 256 | test "GET /issues/:id.xml with empty value for multi custom field" do |
|
257 | 257 | field = CustomField.find(1) |
|
258 | 258 | field.update_attribute :multiple, true |
|
259 | 259 | issue = Issue.find(3) |
|
260 | 260 | issue.custom_field_values = {1 => ['']} |
|
261 | 261 | issue.save! |
|
262 | 262 | |
|
263 | 263 | get '/issues/3.xml' |
|
264 | 264 | |
|
265 | 265 | assert_select 'issue custom_fields[type=array]' do |
|
266 | 266 | assert_select 'custom_field[id="1"]' do |
|
267 | 267 | assert_select 'value[type=array]:empty' |
|
268 | 268 | end |
|
269 | 269 | end |
|
270 | 270 | xml = Hash.from_xml(response.body) |
|
271 | 271 | custom_fields = xml['issue']['custom_fields'] |
|
272 | 272 | assert_kind_of Array, custom_fields |
|
273 | 273 | field = custom_fields.detect {|f| f['id'] == '1'} |
|
274 | 274 | assert_kind_of Hash, field |
|
275 | 275 | assert_equal [], field['value'] |
|
276 | 276 | end |
|
277 | 277 | |
|
278 | 278 | test "GET /issues/:id.json with empty value for multi custom field" do |
|
279 | 279 | field = CustomField.find(1) |
|
280 | 280 | field.update_attribute :multiple, true |
|
281 | 281 | issue = Issue.find(3) |
|
282 | 282 | issue.custom_field_values = {1 => ['']} |
|
283 | 283 | issue.save! |
|
284 | 284 | |
|
285 | 285 | get '/issues/3.json' |
|
286 | 286 | assert_response :success |
|
287 | 287 | json = ActiveSupport::JSON.decode(response.body) |
|
288 | 288 | custom_fields = json['issue']['custom_fields'] |
|
289 | 289 | assert_kind_of Array, custom_fields |
|
290 | 290 | field = custom_fields.detect {|f| f['id'] == 1} |
|
291 | 291 | assert_kind_of Hash, field |
|
292 | 292 | assert_equal [], field['value'].sort |
|
293 | 293 | end |
|
294 | 294 | |
|
295 | 295 | test "GET /issues/:id.xml with attachments" do |
|
296 | 296 | get '/issues/3.xml?include=attachments' |
|
297 | 297 | |
|
298 | 298 | assert_select 'issue attachments[type=array]' do |
|
299 | 299 | assert_select 'attachment', 4 |
|
300 | 300 | assert_select 'attachment id', :text => '1' do |
|
301 | 301 | assert_select '~ filename', :text => 'error281.txt' |
|
302 | 302 | assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/1/error281.txt' |
|
303 | 303 | end |
|
304 | 304 | end |
|
305 | 305 | end |
|
306 | 306 | |
|
307 | 307 | test "GET /issues/:id.xml with subtasks" do |
|
308 | 308 | issue = Issue.generate_with_descendants!(:project_id => 1) |
|
309 | 309 | get "/issues/#{issue.id}.xml?include=children" |
|
310 | 310 | |
|
311 | 311 | assert_select 'issue id', :text => issue.id.to_s do |
|
312 | 312 | assert_select '~ children[type=array] > issue', 2 |
|
313 | 313 | assert_select '~ children[type=array] > issue > children', 1 |
|
314 | 314 | end |
|
315 | 315 | end |
|
316 | 316 | |
|
317 | 317 | test "GET /issues/:id.json with subtasks" do |
|
318 | 318 | issue = Issue.generate_with_descendants!(:project_id => 1) |
|
319 | 319 | get "/issues/#{issue.id}.json?include=children" |
|
320 | 320 | |
|
321 | 321 | json = ActiveSupport::JSON.decode(response.body) |
|
322 | 322 | assert_equal 2, json['issue']['children'].size |
|
323 | 323 | assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size |
|
324 | 324 | end |
|
325 | 325 | |
|
326 | 326 | def test_show_should_include_issue_attributes |
|
327 | 327 | get '/issues/1.xml' |
|
328 | 328 | assert_select 'issue>is_private', :text => 'false' |
|
329 | 329 | end |
|
330 | 330 | |
|
331 | 331 | test "GET /issues/:id.xml?include=watchers should include watchers" do |
|
332 | 332 | Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) |
|
333 | 333 | |
|
334 | 334 | get '/issues/1.xml?include=watchers', {}, credentials('jsmith') |
|
335 | 335 | |
|
336 | 336 | assert_response :ok |
|
337 | 337 | assert_equal 'application/xml', response.content_type |
|
338 | 338 | assert_select 'issue' do |
|
339 | 339 | assert_select 'watchers', Issue.find(1).watchers.count |
|
340 | 340 | assert_select 'watchers' do |
|
341 | 341 | assert_select 'user[id="3"]' |
|
342 | 342 | end |
|
343 | 343 | end |
|
344 | 344 | end |
|
345 | 345 | |
|
346 | 346 | test "GET /issues/:id.xml should not disclose associated changesets from projects the user has no access to" do |
|
347 | 347 | project = Project.generate!(:is_public => false) |
|
348 | 348 | repository = Repository::Subversion.create!(:project => project, :url => "svn://localhost") |
|
349 | 349 | Issue.find(1).changesets << Changeset.generate!(:repository => repository) |
|
350 | 350 | assert Issue.find(1).changesets.any? |
|
351 | 351 | |
|
352 | 352 | get '/issues/1.xml?include=changesets', {}, credentials('jsmith') |
|
353 | 353 | |
|
354 | 354 | # the user jsmith has no permission to view the associated changeset |
|
355 | 355 | assert_select 'issue changesets[type=array]' do |
|
356 | 356 | assert_select 'changeset', 0 |
|
357 | 357 | end |
|
358 | 358 | end |
|
359 | 359 | |
|
360 | 360 | test "GET /issues/:id.xml should contains total_estimated_hours and total_spent_hours" do |
|
361 | 361 | parent = Issue.find(3) |
|
362 | 362 | parent.update_columns :estimated_hours => 2.0 |
|
363 | 363 | child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0) |
|
364 | 364 | TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today, |
|
365 | 365 | :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id) |
|
366 | 366 | get '/issues/3.xml' |
|
367 | 367 | |
|
368 | 368 | assert_equal 'application/xml', response.content_type |
|
369 | 369 | assert_select 'issue' do |
|
370 | 370 | assert_select 'estimated_hours', parent.estimated_hours.to_s |
|
371 | 371 | assert_select 'total_estimated_hours', (parent.estimated_hours.to_f + 3.0).to_s |
|
372 | 372 | assert_select 'spent_hours', parent.spent_hours.to_s |
|
373 | 373 | assert_select 'total_spent_hours', (parent.spent_hours.to_f + 2.5).to_s |
|
374 | 374 | end |
|
375 | 375 | end |
|
376 | 376 | |
|
377 | 377 | test "GET /issues/:id.xml should contains total_estimated_hours, and should not contains spent_hours and total_spent_hours when permission does not exists" do |
|
378 | 378 | parent = Issue.find(3) |
|
379 | 379 | parent.update_columns :estimated_hours => 2.0 |
|
380 | 380 | child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0) |
|
381 | 381 | # remove permission! |
|
382 | 382 | Role.anonymous.remove_permission! :view_time_entries |
|
383 | 383 | #Role.all.each { |role| role.remove_permission! :view_time_entries } |
|
384 | 384 | get '/issues/3.xml' |
|
385 | 385 | |
|
386 | 386 | assert_equal 'application/xml', response.content_type |
|
387 | 387 | assert_select 'issue' do |
|
388 | 388 | assert_select 'estimated_hours', parent.estimated_hours.to_s |
|
389 | 389 | assert_select 'total_estimated_hours', (parent.estimated_hours.to_f + 3.0).to_s |
|
390 | 390 | assert_select 'spent_hours', false |
|
391 | 391 | assert_select 'total_spent_hours', false |
|
392 | 392 | end |
|
393 | 393 | end |
|
394 | 394 | |
|
395 | test "GET /issues/:id.xml should contains visible spent_hours only" do | |
|
396 | user = User.find_by_login('jsmith') | |
|
397 | Role.find(1).update(:time_entries_visibility => 'own') | |
|
398 | parent = Issue.find(3) | |
|
399 | child = Issue.generate!(:parent_issue_id => parent.id) | |
|
400 | TimeEntry.generate!(:user => user, :hours => 5.5, :issue_id => parent.id) | |
|
401 | TimeEntry.generate!(:user => user, :hours => 2, :issue_id => child.id) | |
|
402 | TimeEntry.generate!(:user => User.find(1), :hours => 100, :issue_id => child.id) | |
|
403 | get '/issues/3.xml', {} , credentials(user.login) | |
|
404 | ||
|
405 | assert_equal 'application/xml', response.content_type | |
|
406 | assert_select 'issue' do | |
|
407 | assert_select 'spent_hours', '5.5' | |
|
408 | assert_select 'total_spent_hours', '7.5' | |
|
409 | end | |
|
410 | end | |
|
411 | ||
|
395 | 412 | test "GET /issues/:id.json should contains total_estimated_hours and total_spent_hours" do |
|
396 | 413 | parent = Issue.find(3) |
|
397 | 414 | parent.update_columns :estimated_hours => 2.0 |
|
398 | 415 | child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0) |
|
399 | 416 | TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today, |
|
400 | 417 | :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id) |
|
401 | 418 | get '/issues/3.json' |
|
402 | 419 | |
|
403 | 420 | assert_equal 'application/json', response.content_type |
|
404 | 421 | json = ActiveSupport::JSON.decode(response.body) |
|
405 | 422 | assert_equal parent.estimated_hours, json['issue']['estimated_hours'] |
|
406 | 423 | assert_equal (parent.estimated_hours.to_f + 3.0), json['issue']['total_estimated_hours'] |
|
407 | 424 | assert_equal parent.spent_hours, json['issue']['spent_hours'] |
|
408 | 425 | assert_equal (parent.spent_hours.to_f + 2.5), json['issue']['total_spent_hours'] |
|
409 | 426 | end |
|
410 | 427 | |
|
411 | 428 | test "GET /issues/:id.json should contains total_estimated_hours, and should not contains spent_hours and total_spent_hours when permission does not exists" do |
|
412 | 429 | parent = Issue.find(3) |
|
413 | 430 | parent.update_columns :estimated_hours => 2.0 |
|
414 | 431 | child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0) |
|
415 | 432 | # remove permission! |
|
416 | 433 | Role.anonymous.remove_permission! :view_time_entries |
|
417 | 434 | #Role.all.each { |role| role.remove_permission! :view_time_entries } |
|
418 | 435 | get '/issues/3.json' |
|
419 | 436 | |
|
420 | 437 | assert_equal 'application/json', response.content_type |
|
421 | 438 | json = ActiveSupport::JSON.decode(response.body) |
|
422 | 439 | assert_equal parent.estimated_hours, json['issue']['estimated_hours'] |
|
423 | 440 | assert_equal (parent.estimated_hours.to_f + 3.0), json['issue']['total_estimated_hours'] |
|
424 | 441 | assert_nil json['issue']['spent_hours'] |
|
425 | 442 | assert_nil json['issue']['total_spent_hours'] |
|
426 | 443 | end |
|
427 | 444 | |
|
445 | test "GET /issues/:id.json should contains visible spent_hours only" do | |
|
446 | user = User.find_by_login('jsmith') | |
|
447 | Role.find(1).update(:time_entries_visibility => 'own') | |
|
448 | parent = Issue.find(3) | |
|
449 | child = Issue.generate!(:parent_issue_id => parent.id) | |
|
450 | TimeEntry.generate!(:user => user, :hours => 5.5, :issue_id => parent.id) | |
|
451 | TimeEntry.generate!(:user => user, :hours => 2, :issue_id => child.id) | |
|
452 | TimeEntry.generate!(:user => User.find(1), :hours => 100, :issue_id => child.id) | |
|
453 | get '/issues/3.json', {} , credentials(user.login) | |
|
454 | ||
|
455 | assert_equal 'application/json', response.content_type | |
|
456 | json = ActiveSupport::JSON.decode(response.body) | |
|
457 | assert_equal 5.5, json['issue']['spent_hours'] | |
|
458 | assert_equal 7.5, json['issue']['total_spent_hours'] | |
|
459 | end | |
|
460 | ||
|
428 | 461 | test "POST /issues.xml should create an issue with the attributes" do |
|
429 | 462 | |
|
430 | 463 | payload = <<-XML |
|
431 | 464 | <?xml version="1.0" encoding="UTF-8" ?> |
|
432 | 465 | <issue> |
|
433 | 466 | <project_id>1</project_id> |
|
434 | 467 | <tracker_id>2</tracker_id> |
|
435 | 468 | <status_id>3</status_id> |
|
436 | 469 | <subject>API test</subject> |
|
437 | 470 | </issue> |
|
438 | 471 | XML |
|
439 | 472 | |
|
440 | 473 | assert_difference('Issue.count') do |
|
441 | 474 | post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) |
|
442 | 475 | end |
|
443 | 476 | issue = Issue.order('id DESC').first |
|
444 | 477 | assert_equal 1, issue.project_id |
|
445 | 478 | assert_equal 2, issue.tracker_id |
|
446 | 479 | assert_equal 3, issue.status_id |
|
447 | 480 | assert_equal 'API test', issue.subject |
|
448 | 481 | |
|
449 | 482 | assert_response :created |
|
450 | 483 | assert_equal 'application/xml', @response.content_type |
|
451 | 484 | assert_select 'issue > id', :text => issue.id.to_s |
|
452 | 485 | end |
|
453 | 486 | |
|
454 | 487 | test "POST /issues.xml with watcher_user_ids should create issue with watchers" do |
|
455 | 488 | assert_difference('Issue.count') do |
|
456 | 489 | post '/issues.xml', |
|
457 | 490 | {:issue => {:project_id => 1, :subject => 'Watchers', |
|
458 | 491 | :tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1]}}, credentials('jsmith') |
|
459 | 492 | assert_response :created |
|
460 | 493 | end |
|
461 | 494 | issue = Issue.order('id desc').first |
|
462 | 495 | assert_equal 2, issue.watchers.size |
|
463 | 496 | assert_equal [1, 3], issue.watcher_user_ids.sort |
|
464 | 497 | end |
|
465 | 498 | |
|
466 | 499 | test "POST /issues.xml with failure should return errors" do |
|
467 | 500 | assert_no_difference('Issue.count') do |
|
468 | 501 | post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith') |
|
469 | 502 | end |
|
470 | 503 | |
|
471 | 504 | assert_select 'errors error', :text => "Subject cannot be blank" |
|
472 | 505 | end |
|
473 | 506 | |
|
474 | 507 | test "POST /issues.json should create an issue with the attributes" do |
|
475 | 508 | |
|
476 | 509 | payload = <<-JSON |
|
477 | 510 | { |
|
478 | 511 | "issue": { |
|
479 | 512 | "project_id": "1", |
|
480 | 513 | "tracker_id": "2", |
|
481 | 514 | "status_id": "3", |
|
482 | 515 | "subject": "API test" |
|
483 | 516 | } |
|
484 | 517 | } |
|
485 | 518 | JSON |
|
486 | 519 | |
|
487 | 520 | assert_difference('Issue.count') do |
|
488 | 521 | post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) |
|
489 | 522 | end |
|
490 | 523 | |
|
491 | 524 | issue = Issue.order('id DESC').first |
|
492 | 525 | assert_equal 1, issue.project_id |
|
493 | 526 | assert_equal 2, issue.tracker_id |
|
494 | 527 | assert_equal 3, issue.status_id |
|
495 | 528 | assert_equal 'API test', issue.subject |
|
496 | 529 | end |
|
497 | 530 | |
|
498 | 531 | test "POST /issues.json should accept project identifier as project_id" do |
|
499 | 532 | assert_difference('Issue.count') do |
|
500 | 533 | post '/issues.json', |
|
501 | 534 | {:issue => {:project_id => 'subproject1', :tracker_id => 2, :subject => 'Foo'}}, |
|
502 | 535 | credentials('jsmith') |
|
503 | 536 | |
|
504 | 537 | assert_response :created |
|
505 | 538 | end |
|
506 | 539 | end |
|
507 | 540 | |
|
508 | 541 | test "POST /issues.json without tracker_id should accept custom fields" do |
|
509 | 542 | field = IssueCustomField.generate!( |
|
510 | 543 | :field_format => 'list', |
|
511 | 544 | :multiple => true, |
|
512 | 545 | :possible_values => ["V1", "V2", "V3"], |
|
513 | 546 | :default_value => "V2", |
|
514 | 547 | :is_for_all => true, |
|
515 | 548 | :trackers => Tracker.all.to_a |
|
516 | 549 | ) |
|
517 | 550 | |
|
518 | 551 | payload = <<-JSON |
|
519 | 552 | { |
|
520 | 553 | "issue": { |
|
521 | 554 | "project_id": "1", |
|
522 | 555 | "subject": "Multivalued custom field", |
|
523 | 556 | "custom_field_values":{"#{field.id}":["V1","V3"]} |
|
524 | 557 | } |
|
525 | 558 | } |
|
526 | 559 | JSON |
|
527 | 560 | |
|
528 | 561 | assert_difference('Issue.count') do |
|
529 | 562 | post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) |
|
530 | 563 | end |
|
531 | 564 | |
|
532 | 565 | assert_response :created |
|
533 | 566 | issue = Issue.order('id DESC').first |
|
534 | 567 | assert_equal ["V1", "V3"], issue.custom_field_value(field).sort |
|
535 | 568 | end |
|
536 | 569 | |
|
537 | 570 | test "POST /issues.json with omitted custom field should set default value" do |
|
538 | 571 | field = IssueCustomField.generate!(:default_value => "Default") |
|
539 | 572 | |
|
540 | 573 | issue = new_record(Issue) do |
|
541 | 574 | post '/issues.json', |
|
542 | 575 | {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {}}}, |
|
543 | 576 | credentials('jsmith') |
|
544 | 577 | end |
|
545 | 578 | assert_equal "Default", issue.custom_field_value(field) |
|
546 | 579 | end |
|
547 | 580 | |
|
548 | 581 | test "POST /issues.json with custom field set to blank should not set default value" do |
|
549 | 582 | field = IssueCustomField.generate!(:default_value => "Default") |
|
550 | 583 | |
|
551 | 584 | issue = new_record(Issue) do |
|
552 | 585 | post '/issues.json', |
|
553 | 586 | {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {field.id.to_s => ""}}}, |
|
554 | 587 | credentials('jsmith') |
|
555 | 588 | end |
|
556 | 589 | assert_equal "", issue.custom_field_value(field) |
|
557 | 590 | end |
|
558 | 591 | |
|
559 | 592 | test "POST /issues.json with failure should return errors" do |
|
560 | 593 | assert_no_difference('Issue.count') do |
|
561 | 594 | post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith') |
|
562 | 595 | end |
|
563 | 596 | |
|
564 | 597 | json = ActiveSupport::JSON.decode(response.body) |
|
565 | 598 | assert json['errors'].include?("Subject cannot be blank") |
|
566 | 599 | end |
|
567 | 600 | |
|
568 | 601 | test "POST /issues.json with invalid project_id should respond with 422" do |
|
569 | 602 | post '/issues.json', {:issue => {:project_id => 999, :subject => "API"}}, credentials('jsmith') |
|
570 | 603 | assert_response 422 |
|
571 | 604 | end |
|
572 | 605 | |
|
573 | 606 | test "PUT /issues/:id.xml" do |
|
574 | 607 | assert_difference('Journal.count') do |
|
575 | 608 | put '/issues/6.xml', |
|
576 | 609 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
|
577 | 610 | credentials('jsmith') |
|
578 | 611 | end |
|
579 | 612 | |
|
580 | 613 | issue = Issue.find(6) |
|
581 | 614 | assert_equal "API update", issue.subject |
|
582 | 615 | journal = Journal.last |
|
583 | 616 | assert_equal "A new note", journal.notes |
|
584 | 617 | end |
|
585 | 618 | |
|
586 | 619 | test "PUT /issues/:id.xml with custom fields" do |
|
587 | 620 | put '/issues/3.xml', |
|
588 | 621 | {:issue => {:custom_fields => [ |
|
589 | 622 | {'id' => '1', 'value' => 'PostgreSQL' }, |
|
590 | 623 | {'id' => '2', 'value' => '150'} |
|
591 | 624 | ]}}, |
|
592 | 625 | credentials('jsmith') |
|
593 | 626 | |
|
594 | 627 | issue = Issue.find(3) |
|
595 | 628 | assert_equal '150', issue.custom_value_for(2).value |
|
596 | 629 | assert_equal 'PostgreSQL', issue.custom_value_for(1).value |
|
597 | 630 | end |
|
598 | 631 | |
|
599 | 632 | test "PUT /issues/:id.xml with multi custom fields" do |
|
600 | 633 | field = CustomField.find(1) |
|
601 | 634 | field.update_attribute :multiple, true |
|
602 | 635 | |
|
603 | 636 | put '/issues/3.xml', |
|
604 | 637 | {:issue => {:custom_fields => [ |
|
605 | 638 | {'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, |
|
606 | 639 | {'id' => '2', 'value' => '150'} |
|
607 | 640 | ]}}, |
|
608 | 641 | credentials('jsmith') |
|
609 | 642 | |
|
610 | 643 | issue = Issue.find(3) |
|
611 | 644 | assert_equal '150', issue.custom_value_for(2).value |
|
612 | 645 | assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort |
|
613 | 646 | end |
|
614 | 647 | |
|
615 | 648 | test "PUT /issues/:id.xml with project change" do |
|
616 | 649 | put '/issues/3.xml', |
|
617 | 650 | {:issue => {:project_id => 2, :subject => 'Project changed'}}, |
|
618 | 651 | credentials('jsmith') |
|
619 | 652 | |
|
620 | 653 | issue = Issue.find(3) |
|
621 | 654 | assert_equal 2, issue.project_id |
|
622 | 655 | assert_equal 'Project changed', issue.subject |
|
623 | 656 | end |
|
624 | 657 | |
|
625 | 658 | test "PUT /issues/:id.xml with notes only" do |
|
626 | 659 | assert_difference('Journal.count') do |
|
627 | 660 | put '/issues/6.xml', |
|
628 | 661 | {:issue => {:notes => 'Notes only'}}, |
|
629 | 662 | credentials('jsmith') |
|
630 | 663 | end |
|
631 | 664 | |
|
632 | 665 | journal = Journal.last |
|
633 | 666 | assert_equal "Notes only", journal.notes |
|
634 | 667 | end |
|
635 | 668 | |
|
636 | 669 | test "PUT /issues/:id.json with omitted custom field should not change blank value to default value" do |
|
637 | 670 | field = IssueCustomField.generate!(:default_value => "Default") |
|
638 | 671 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => ""}) |
|
639 | 672 | assert_equal "", issue.reload.custom_field_value(field) |
|
640 | 673 | |
|
641 | 674 | assert_difference('Journal.count') do |
|
642 | 675 | put "/issues/#{issue.id}.json", |
|
643 | 676 | {:issue => {:custom_field_values => {}, :notes => 'API'}}, |
|
644 | 677 | credentials('jsmith') |
|
645 | 678 | end |
|
646 | 679 | |
|
647 | 680 | assert_equal "", issue.reload.custom_field_value(field) |
|
648 | 681 | end |
|
649 | 682 | |
|
650 | 683 | test "PUT /issues/:id.json with custom field set to blank should not change blank value to default value" do |
|
651 | 684 | field = IssueCustomField.generate!(:default_value => "Default") |
|
652 | 685 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id.to_s => ""}) |
|
653 | 686 | assert_equal "", issue.reload.custom_field_value(field) |
|
654 | 687 | |
|
655 | 688 | assert_difference('Journal.count') do |
|
656 | 689 | put "/issues/#{issue.id}.json", |
|
657 | 690 | {:issue => {:custom_field_values => {field.id.to_s => ""}, :notes => 'API'}}, |
|
658 | 691 | credentials('jsmith') |
|
659 | 692 | end |
|
660 | 693 | |
|
661 | 694 | assert_equal "", issue.reload.custom_field_value(field) |
|
662 | 695 | end |
|
663 | 696 | |
|
664 | 697 | test "PUT /issues/:id.json with tracker change and omitted custom field specific to that tracker should set default value" do |
|
665 | 698 | field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2]) |
|
666 | 699 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1) |
|
667 | 700 | |
|
668 | 701 | assert_difference('Journal.count') do |
|
669 | 702 | put "/issues/#{issue.id}.json", |
|
670 | 703 | {:issue => {:tracker_id => 2, :custom_field_values => {}, :notes => 'API'}}, |
|
671 | 704 | credentials('jsmith') |
|
672 | 705 | end |
|
673 | 706 | |
|
674 | 707 | assert_equal 2, issue.reload.tracker_id |
|
675 | 708 | assert_equal "Default", issue.reload.custom_field_value(field) |
|
676 | 709 | end |
|
677 | 710 | |
|
678 | 711 | test "PUT /issues/:id.json with tracker change and custom field specific to that tracker set to blank should not set default value" do |
|
679 | 712 | field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2]) |
|
680 | 713 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1) |
|
681 | 714 | |
|
682 | 715 | assert_difference('Journal.count') do |
|
683 | 716 | put "/issues/#{issue.id}.json", |
|
684 | 717 | {:issue => {:tracker_id => 2, :custom_field_values => {field.id.to_s => ""}, :notes => 'API'}}, |
|
685 | 718 | credentials('jsmith') |
|
686 | 719 | end |
|
687 | 720 | |
|
688 | 721 | assert_equal 2, issue.reload.tracker_id |
|
689 | 722 | assert_equal "", issue.reload.custom_field_value(field) |
|
690 | 723 | end |
|
691 | 724 | |
|
692 | 725 | test "PUT /issues/:id.xml with failed update" do |
|
693 | 726 | put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith') |
|
694 | 727 | |
|
695 | 728 | assert_response :unprocessable_entity |
|
696 | 729 | assert_select 'errors error', :text => "Subject cannot be blank" |
|
697 | 730 | end |
|
698 | 731 | |
|
699 | 732 | test "PUT /issues/:id.json" do |
|
700 | 733 | assert_difference('Journal.count') do |
|
701 | 734 | put '/issues/6.json', |
|
702 | 735 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
|
703 | 736 | credentials('jsmith') |
|
704 | 737 | |
|
705 | 738 | assert_response :ok |
|
706 | 739 | assert_equal '', response.body |
|
707 | 740 | end |
|
708 | 741 | |
|
709 | 742 | issue = Issue.find(6) |
|
710 | 743 | assert_equal "API update", issue.subject |
|
711 | 744 | journal = Journal.last |
|
712 | 745 | assert_equal "A new note", journal.notes |
|
713 | 746 | end |
|
714 | 747 | |
|
715 | 748 | test "PUT /issues/:id.json with failed update" do |
|
716 | 749 | put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith') |
|
717 | 750 | |
|
718 | 751 | assert_response :unprocessable_entity |
|
719 | 752 | json = ActiveSupport::JSON.decode(response.body) |
|
720 | 753 | assert json['errors'].include?("Subject cannot be blank") |
|
721 | 754 | end |
|
722 | 755 | |
|
723 | 756 | test "DELETE /issues/:id.xml" do |
|
724 | 757 | assert_difference('Issue.count', -1) do |
|
725 | 758 | delete '/issues/6.xml', {}, credentials('jsmith') |
|
726 | 759 | |
|
727 | 760 | assert_response :ok |
|
728 | 761 | assert_equal '', response.body |
|
729 | 762 | end |
|
730 | 763 | assert_nil Issue.find_by_id(6) |
|
731 | 764 | end |
|
732 | 765 | |
|
733 | 766 | test "DELETE /issues/:id.json" do |
|
734 | 767 | assert_difference('Issue.count', -1) do |
|
735 | 768 | delete '/issues/6.json', {}, credentials('jsmith') |
|
736 | 769 | |
|
737 | 770 | assert_response :ok |
|
738 | 771 | assert_equal '', response.body |
|
739 | 772 | end |
|
740 | 773 | assert_nil Issue.find_by_id(6) |
|
741 | 774 | end |
|
742 | 775 | |
|
743 | 776 | test "POST /issues/:id/watchers.xml should add watcher" do |
|
744 | 777 | assert_difference 'Watcher.count' do |
|
745 | 778 | post '/issues/1/watchers.xml', {:user_id => 3}, credentials('jsmith') |
|
746 | 779 | |
|
747 | 780 | assert_response :ok |
|
748 | 781 | assert_equal '', response.body |
|
749 | 782 | end |
|
750 | 783 | watcher = Watcher.order('id desc').first |
|
751 | 784 | assert_equal Issue.find(1), watcher.watchable |
|
752 | 785 | assert_equal User.find(3), watcher.user |
|
753 | 786 | end |
|
754 | 787 | |
|
755 | 788 | test "DELETE /issues/:id/watchers/:user_id.xml should remove watcher" do |
|
756 | 789 | Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) |
|
757 | 790 | |
|
758 | 791 | assert_difference 'Watcher.count', -1 do |
|
759 | 792 | delete '/issues/1/watchers/3.xml', {}, credentials('jsmith') |
|
760 | 793 | |
|
761 | 794 | assert_response :ok |
|
762 | 795 | assert_equal '', response.body |
|
763 | 796 | end |
|
764 | 797 | assert_equal false, Issue.find(1).watched_by?(User.find(3)) |
|
765 | 798 | end |
|
766 | 799 | |
|
767 | 800 | def test_create_issue_with_uploaded_file |
|
768 | 801 | token = xml_upload('test_create_with_upload', credentials('jsmith')) |
|
769 | 802 | attachment = Attachment.find_by_token(token) |
|
770 | 803 | |
|
771 | 804 | # create the issue with the upload's token |
|
772 | 805 | assert_difference 'Issue.count' do |
|
773 | 806 | post '/issues.xml', |
|
774 | 807 | {:issue => {:project_id => 1, :subject => 'Uploaded file', |
|
775 | 808 | :uploads => [{:token => token, :filename => 'test.txt', |
|
776 | 809 | :content_type => 'text/plain'}]}}, |
|
777 | 810 | credentials('jsmith') |
|
778 | 811 | assert_response :created |
|
779 | 812 | end |
|
780 | 813 | issue = Issue.order('id DESC').first |
|
781 | 814 | assert_equal 1, issue.attachments.count |
|
782 | 815 | assert_equal attachment, issue.attachments.first |
|
783 | 816 | |
|
784 | 817 | attachment.reload |
|
785 | 818 | assert_equal 'test.txt', attachment.filename |
|
786 | 819 | assert_equal 'text/plain', attachment.content_type |
|
787 | 820 | assert_equal 'test_create_with_upload'.size, attachment.filesize |
|
788 | 821 | assert_equal 2, attachment.author_id |
|
789 | 822 | |
|
790 | 823 | # get the issue with its attachments |
|
791 | 824 | get "/issues/#{issue.id}.xml", :include => 'attachments' |
|
792 | 825 | assert_response :success |
|
793 | 826 | xml = Hash.from_xml(response.body) |
|
794 | 827 | attachments = xml['issue']['attachments'] |
|
795 | 828 | assert_kind_of Array, attachments |
|
796 | 829 | assert_equal 1, attachments.size |
|
797 | 830 | url = attachments.first['content_url'] |
|
798 | 831 | assert_not_nil url |
|
799 | 832 | |
|
800 | 833 | # download the attachment |
|
801 | 834 | get url |
|
802 | 835 | assert_response :success |
|
803 | 836 | assert_equal 'test_create_with_upload', response.body |
|
804 | 837 | end |
|
805 | 838 | |
|
806 | 839 | def test_create_issue_with_multiple_uploaded_files_as_xml |
|
807 | 840 | token1 = xml_upload('File content 1', credentials('jsmith')) |
|
808 | 841 | token2 = xml_upload('File content 2', credentials('jsmith')) |
|
809 | 842 | |
|
810 | 843 | payload = <<-XML |
|
811 | 844 | <?xml version="1.0" encoding="UTF-8" ?> |
|
812 | 845 | <issue> |
|
813 | 846 | <project_id>1</project_id> |
|
814 | 847 | <tracker_id>1</tracker_id> |
|
815 | 848 | <subject>Issue with multiple attachments</subject> |
|
816 | 849 | <uploads type="array"> |
|
817 | 850 | <upload> |
|
818 | 851 | <token>#{token1}</token> |
|
819 | 852 | <filename>test1.txt</filename> |
|
820 | 853 | </upload> |
|
821 | 854 | <upload> |
|
822 | 855 | <token>#{token2}</token> |
|
823 | 856 | <filename>test1.txt</filename> |
|
824 | 857 | </upload> |
|
825 | 858 | </uploads> |
|
826 | 859 | </issue> |
|
827 | 860 | XML |
|
828 | 861 | |
|
829 | 862 | assert_difference 'Issue.count' do |
|
830 | 863 | post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) |
|
831 | 864 | assert_response :created |
|
832 | 865 | end |
|
833 | 866 | issue = Issue.order('id DESC').first |
|
834 | 867 | assert_equal 2, issue.attachments.count |
|
835 | 868 | end |
|
836 | 869 | |
|
837 | 870 | def test_create_issue_with_multiple_uploaded_files_as_json |
|
838 | 871 | token1 = json_upload('File content 1', credentials('jsmith')) |
|
839 | 872 | token2 = json_upload('File content 2', credentials('jsmith')) |
|
840 | 873 | |
|
841 | 874 | payload = <<-JSON |
|
842 | 875 | { |
|
843 | 876 | "issue": { |
|
844 | 877 | "project_id": "1", |
|
845 | 878 | "tracker_id": "1", |
|
846 | 879 | "subject": "Issue with multiple attachments", |
|
847 | 880 | "uploads": [ |
|
848 | 881 | {"token": "#{token1}", "filename": "test1.txt"}, |
|
849 | 882 | {"token": "#{token2}", "filename": "test2.txt"} |
|
850 | 883 | ] |
|
851 | 884 | } |
|
852 | 885 | } |
|
853 | 886 | JSON |
|
854 | 887 | |
|
855 | 888 | assert_difference 'Issue.count' do |
|
856 | 889 | post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) |
|
857 | 890 | assert_response :created |
|
858 | 891 | end |
|
859 | 892 | issue = Issue.order('id DESC').first |
|
860 | 893 | assert_equal 2, issue.attachments.count |
|
861 | 894 | end |
|
862 | 895 | |
|
863 | 896 | def test_update_issue_with_uploaded_file |
|
864 | 897 | token = xml_upload('test_upload_with_upload', credentials('jsmith')) |
|
865 | 898 | attachment = Attachment.find_by_token(token) |
|
866 | 899 | |
|
867 | 900 | # update the issue with the upload's token |
|
868 | 901 | assert_difference 'Journal.count' do |
|
869 | 902 | put '/issues/1.xml', |
|
870 | 903 | {:issue => {:notes => 'Attachment added', |
|
871 | 904 | :uploads => [{:token => token, :filename => 'test.txt', |
|
872 | 905 | :content_type => 'text/plain'}]}}, |
|
873 | 906 | credentials('jsmith') |
|
874 | 907 | assert_response :ok |
|
875 | 908 | assert_equal '', @response.body |
|
876 | 909 | end |
|
877 | 910 | |
|
878 | 911 | issue = Issue.find(1) |
|
879 | 912 | assert_include attachment, issue.attachments |
|
880 | 913 | end |
|
881 | 914 | end |
General Comments 0
You need to be logged in to leave comments.
Login now