##// END OF EJS Templates
Use raw request content in tests to make sure that XML/JSON payload is properly parsed....
Jean-Philippe Lang -
r13410:3fe8197d7323
parent child
Show More
@@ -1,647 +1,665
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 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:content(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:content(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 get '/issues/1.xml?include=journals'
173 173
174 174 assert_select 'issue journals[type=array]' do
175 175 assert_select 'journal[id="1"]' do
176 176 assert_select 'details[type=array]' do
177 177 assert_select 'detail[name=status_id]' do
178 178 assert_select 'old_value', :text => '1'
179 179 assert_select 'new_value', :text => '2'
180 180 end
181 181 end
182 182 end
183 183 end
184 184 end
185 185
186 186 test "GET /issues/:id.xml with custom fields" do
187 187 get '/issues/3.xml'
188 188
189 189 assert_select 'issue custom_fields[type=array]' do
190 190 assert_select 'custom_field[id="1"]' do
191 191 assert_select 'value', :text => 'MySQL'
192 192 end
193 193 end
194 194 assert_nothing_raised do
195 195 Hash.from_xml(response.body).to_xml
196 196 end
197 197 end
198 198
199 199 test "GET /issues/:id.xml with multi custom fields" do
200 200 field = CustomField.find(1)
201 201 field.update_attribute :multiple, true
202 202 issue = Issue.find(3)
203 203 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
204 204 issue.save!
205 205
206 206 get '/issues/3.xml'
207 207 assert_response :success
208 208
209 209 assert_select 'issue custom_fields[type=array]' do
210 210 assert_select 'custom_field[id="1"]' do
211 211 assert_select 'value[type=array] value', 2
212 212 end
213 213 end
214 214 xml = Hash.from_xml(response.body)
215 215 custom_fields = xml['issue']['custom_fields']
216 216 assert_kind_of Array, custom_fields
217 217 field = custom_fields.detect {|f| f['id'] == '1'}
218 218 assert_kind_of Hash, field
219 219 assert_equal ['MySQL', 'Oracle'], field['value'].sort
220 220 end
221 221
222 222 test "GET /issues/:id.json with multi custom fields" do
223 223 field = CustomField.find(1)
224 224 field.update_attribute :multiple, true
225 225 issue = Issue.find(3)
226 226 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
227 227 issue.save!
228 228
229 229 get '/issues/3.json'
230 230 assert_response :success
231 231
232 232 json = ActiveSupport::JSON.decode(response.body)
233 233 custom_fields = json['issue']['custom_fields']
234 234 assert_kind_of Array, custom_fields
235 235 field = custom_fields.detect {|f| f['id'] == 1}
236 236 assert_kind_of Hash, field
237 237 assert_equal ['MySQL', 'Oracle'], field['value'].sort
238 238 end
239 239
240 240 test "GET /issues/:id.xml with empty value for multi custom field" do
241 241 field = CustomField.find(1)
242 242 field.update_attribute :multiple, true
243 243 issue = Issue.find(3)
244 244 issue.custom_field_values = {1 => ['']}
245 245 issue.save!
246 246
247 247 get '/issues/3.xml'
248 248
249 249 assert_select 'issue custom_fields[type=array]' do
250 250 assert_select 'custom_field[id="1"]' do
251 251 assert_select 'value[type=array]:empty'
252 252 end
253 253 end
254 254 xml = Hash.from_xml(response.body)
255 255 custom_fields = xml['issue']['custom_fields']
256 256 assert_kind_of Array, custom_fields
257 257 field = custom_fields.detect {|f| f['id'] == '1'}
258 258 assert_kind_of Hash, field
259 259 assert_equal [], field['value']
260 260 end
261 261
262 262 test "GET /issues/:id.json with empty value for multi custom field" do
263 263 field = CustomField.find(1)
264 264 field.update_attribute :multiple, true
265 265 issue = Issue.find(3)
266 266 issue.custom_field_values = {1 => ['']}
267 267 issue.save!
268 268
269 269 get '/issues/3.json'
270 270 assert_response :success
271 271 json = ActiveSupport::JSON.decode(response.body)
272 272 custom_fields = json['issue']['custom_fields']
273 273 assert_kind_of Array, custom_fields
274 274 field = custom_fields.detect {|f| f['id'] == 1}
275 275 assert_kind_of Hash, field
276 276 assert_equal [], field['value'].sort
277 277 end
278 278
279 279 test "GET /issues/:id.xml with attachments" do
280 280 get '/issues/3.xml?include=attachments'
281 281
282 282 assert_select 'issue attachments[type=array]' do
283 283 assert_select 'attachment', 5
284 284 assert_select 'attachment id:content(4)' do
285 285 assert_select '~ filename', :text => 'source.rb'
286 286 assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/4/source.rb'
287 287 end
288 288 end
289 289 end
290 290
291 291 test "GET /issues/:id.xml with subtasks" do
292 292 issue = Issue.generate_with_descendants!(:project_id => 1)
293 293 get "/issues/#{issue.id}.xml?include=children"
294 294
295 295 assert_select 'issue children[type=array]' do
296 296 assert_select 'issue', 2
297 297 assert_select 'issue children', 1
298 298 end
299 299 end
300 300
301 301 test "GET /issues/:id.json with subtasks" do
302 302 issue = Issue.generate_with_descendants!(:project_id => 1)
303 303 get "/issues/#{issue.id}.json?include=children"
304 304
305 305 json = ActiveSupport::JSON.decode(response.body)
306 306 assert_equal 2, json['issue']['children'].size
307 307 assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size
308 308 end
309 309
310 310 def test_show_should_include_issue_attributes
311 311 get '/issues/1.xml'
312 312 assert_select 'issue>is_private', :text => 'false'
313 313 end
314 314
315 315 test "GET /issues/:id.xml?include=watchers should include watchers" do
316 316 Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
317 317
318 318 get '/issues/1.xml?include=watchers', {}, credentials('jsmith')
319 319
320 320 assert_response :ok
321 321 assert_equal 'application/xml', response.content_type
322 322 assert_select 'issue' do
323 323 assert_select 'watchers', Issue.find(1).watchers.count
324 324 assert_select 'watchers' do
325 325 assert_select 'user[id=3]'
326 326 end
327 327 end
328 328 end
329 329
330 330 test "POST /issues.xml should create an issue with the attributes" do
331
332 payload = <<-XML
333 <?xml version="1.0" encoding="UTF-8" ?>
334 <issue>
335 <project_id>1</project_id>
336 <tracker_id>2</tracker_id>
337 <status_id>3</status_id>
338 <subject>API test</subject>
339 </issue>
340 XML
341
331 342 assert_difference('Issue.count') do
332 post '/issues.xml',
333 {:issue => {:project_id => 1, :subject => 'API test',
334 :tracker_id => 2, :status_id => 3}}, credentials('jsmith')
343 post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
335 344 end
336 345 issue = Issue.order('id DESC').first
337 346 assert_equal 1, issue.project_id
338 347 assert_equal 2, issue.tracker_id
339 348 assert_equal 3, issue.status_id
340 349 assert_equal 'API test', issue.subject
341 350
342 351 assert_response :created
343 352 assert_equal 'application/xml', @response.content_type
344 353 assert_select 'issue > id', :text => issue.id.to_s
345 354 end
346 355
347 356 test "POST /issues.xml with watcher_user_ids should create issue with watchers" do
348 357 assert_difference('Issue.count') do
349 358 post '/issues.xml',
350 359 {:issue => {:project_id => 1, :subject => 'Watchers',
351 360 :tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1]}}, credentials('jsmith')
352 361 assert_response :created
353 362 end
354 363 issue = Issue.order('id desc').first
355 364 assert_equal 2, issue.watchers.size
356 365 assert_equal [1, 3], issue.watcher_user_ids.sort
357 366 end
358 367
359 368 test "POST /issues.xml with failure should return errors" do
360 369 assert_no_difference('Issue.count') do
361 370 post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith')
362 371 end
363 372
364 373 assert_select 'errors error', :text => "Subject cannot be blank"
365 374 end
366 375
367 376 test "POST /issues.json should create an issue with the attributes" do
377
378 payload = <<-JSON
379 {
380 "issue": {
381 "project_id": "1",
382 "tracker_id": "2",
383 "status_id": "3",
384 "subject": "API test"
385 }
386 }
387 JSON
388
368 389 assert_difference('Issue.count') do
369 post '/issues.json',
370 {:issue => {:project_id => 1, :subject => 'API test',
371 :tracker_id => 2, :status_id => 3}},
372 credentials('jsmith')
390 post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
373 391 end
374 392
375 393 issue = Issue.order('id DESC').first
376 394 assert_equal 1, issue.project_id
377 395 assert_equal 2, issue.tracker_id
378 396 assert_equal 3, issue.status_id
379 397 assert_equal 'API test', issue.subject
380 398 end
381 399
382 400 test "POST /issues.json with failure should return errors" do
383 401 assert_no_difference('Issue.count') do
384 402 post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith')
385 403 end
386 404
387 405 json = ActiveSupport::JSON.decode(response.body)
388 406 assert json['errors'].include?("Subject cannot be blank")
389 407 end
390 408
391 409 test "PUT /issues/:id.xml" do
392 410 assert_difference('Journal.count') do
393 411 put '/issues/6.xml',
394 412 {:issue => {:subject => 'API update', :notes => 'A new note'}},
395 413 credentials('jsmith')
396 414 end
397 415
398 416 issue = Issue.find(6)
399 417 assert_equal "API update", issue.subject
400 418 journal = Journal.last
401 419 assert_equal "A new note", journal.notes
402 420 end
403 421
404 422 test "PUT /issues/:id.xml with custom fields" do
405 423 put '/issues/3.xml',
406 424 {:issue => {:custom_fields => [
407 425 {'id' => '1', 'value' => 'PostgreSQL' },
408 426 {'id' => '2', 'value' => '150'}
409 427 ]}},
410 428 credentials('jsmith')
411 429
412 430 issue = Issue.find(3)
413 431 assert_equal '150', issue.custom_value_for(2).value
414 432 assert_equal 'PostgreSQL', issue.custom_value_for(1).value
415 433 end
416 434
417 435 test "PUT /issues/:id.xml with multi custom fields" do
418 436 field = CustomField.find(1)
419 437 field.update_attribute :multiple, true
420 438
421 439 put '/issues/3.xml',
422 440 {:issue => {:custom_fields => [
423 441 {'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] },
424 442 {'id' => '2', 'value' => '150'}
425 443 ]}},
426 444 credentials('jsmith')
427 445
428 446 issue = Issue.find(3)
429 447 assert_equal '150', issue.custom_value_for(2).value
430 448 assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort
431 449 end
432 450
433 451 test "PUT /issues/:id.xml with project change" do
434 452 put '/issues/3.xml',
435 453 {:issue => {:project_id => 2, :subject => 'Project changed'}},
436 454 credentials('jsmith')
437 455
438 456 issue = Issue.find(3)
439 457 assert_equal 2, issue.project_id
440 458 assert_equal 'Project changed', issue.subject
441 459 end
442 460
443 461 test "PUT /issues/:id.xml with failed update" do
444 462 put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith')
445 463
446 464 assert_response :unprocessable_entity
447 465 assert_select 'errors error', :text => "Subject cannot be blank"
448 466 end
449 467
450 468 test "PUT /issues/:id.json" do
451 469 assert_difference('Journal.count') do
452 470 put '/issues/6.json',
453 471 {:issue => {:subject => 'API update', :notes => 'A new note'}},
454 472 credentials('jsmith')
455 473
456 474 assert_response :ok
457 475 assert_equal '', response.body
458 476 end
459 477
460 478 issue = Issue.find(6)
461 479 assert_equal "API update", issue.subject
462 480 journal = Journal.last
463 481 assert_equal "A new note", journal.notes
464 482 end
465 483
466 484 test "PUT /issues/:id.json with failed update" do
467 485 put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
468 486
469 487 assert_response :unprocessable_entity
470 488 json = ActiveSupport::JSON.decode(response.body)
471 489 assert json['errors'].include?("Subject cannot be blank")
472 490 end
473 491
474 492 test "DELETE /issues/:id.xml" do
475 493 assert_difference('Issue.count', -1) do
476 494 delete '/issues/6.xml', {}, credentials('jsmith')
477 495
478 496 assert_response :ok
479 497 assert_equal '', response.body
480 498 end
481 499 assert_nil Issue.find_by_id(6)
482 500 end
483 501
484 502 test "DELETE /issues/:id.json" do
485 503 assert_difference('Issue.count', -1) do
486 504 delete '/issues/6.json', {}, credentials('jsmith')
487 505
488 506 assert_response :ok
489 507 assert_equal '', response.body
490 508 end
491 509 assert_nil Issue.find_by_id(6)
492 510 end
493 511
494 512 test "POST /issues/:id/watchers.xml should add watcher" do
495 513 assert_difference 'Watcher.count' do
496 514 post '/issues/1/watchers.xml', {:user_id => 3}, credentials('jsmith')
497 515
498 516 assert_response :ok
499 517 assert_equal '', response.body
500 518 end
501 519 watcher = Watcher.order('id desc').first
502 520 assert_equal Issue.find(1), watcher.watchable
503 521 assert_equal User.find(3), watcher.user
504 522 end
505 523
506 524 test "DELETE /issues/:id/watchers/:user_id.xml should remove watcher" do
507 525 Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
508 526
509 527 assert_difference 'Watcher.count', -1 do
510 528 delete '/issues/1/watchers/3.xml', {}, credentials('jsmith')
511 529
512 530 assert_response :ok
513 531 assert_equal '', response.body
514 532 end
515 533 assert_equal false, Issue.find(1).watched_by?(User.find(3))
516 534 end
517 535
518 536 def test_create_issue_with_uploaded_file
519 537 set_tmp_attachments_directory
520 538 # upload the file
521 539 assert_difference 'Attachment.count' do
522 540 post '/uploads.xml', 'test_create_with_upload',
523 541 {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
524 542 assert_response :created
525 543 end
526 544 xml = Hash.from_xml(response.body)
527 545 token = xml['upload']['token']
528 546 attachment = Attachment.order('id DESC').first
529 547
530 548 # create the issue with the upload's token
531 549 assert_difference 'Issue.count' do
532 550 post '/issues.xml',
533 551 {:issue => {:project_id => 1, :subject => 'Uploaded file',
534 552 :uploads => [{:token => token, :filename => 'test.txt',
535 553 :content_type => 'text/plain'}]}},
536 554 credentials('jsmith')
537 555 assert_response :created
538 556 end
539 557 issue = Issue.order('id DESC').first
540 558 assert_equal 1, issue.attachments.count
541 559 assert_equal attachment, issue.attachments.first
542 560
543 561 attachment.reload
544 562 assert_equal 'test.txt', attachment.filename
545 563 assert_equal 'text/plain', attachment.content_type
546 564 assert_equal 'test_create_with_upload'.size, attachment.filesize
547 565 assert_equal 2, attachment.author_id
548 566
549 567 # get the issue with its attachments
550 568 get "/issues/#{issue.id}.xml", :include => 'attachments'
551 569 assert_response :success
552 570 xml = Hash.from_xml(response.body)
553 571 attachments = xml['issue']['attachments']
554 572 assert_kind_of Array, attachments
555 573 assert_equal 1, attachments.size
556 574 url = attachments.first['content_url']
557 575 assert_not_nil url
558 576
559 577 # download the attachment
560 578 get url
561 579 assert_response :success
562 580 end
563 581
564 582 def test_create_issue_with_multiple_uploaded_files_as_xml
565 583 token1 = xml_upload('File content 1', credentials('jsmith'))
566 584 token2 = xml_upload('File content 2', credentials('jsmith'))
567 585
568 586 payload = <<-XML
569 587 <?xml version="1.0" encoding="UTF-8" ?>
570 588 <issue>
571 589 <project_id>1</project_id>
572 590 <tracker_id>1</tracker_id>
573 591 <subject>Issue with multiple attachments</subject>
574 592 <uploads type="array">
575 593 <upload>
576 594 <token>#{token1}</token>
577 595 <filename>test1.txt</filename>
578 596 </upload>
579 597 <upload>
580 598 <token>#{token2}</token>
581 599 <filename>test1.txt</filename>
582 600 </upload>
583 601 </uploads>
584 602 </issue>
585 603 XML
586 604
587 605 assert_difference 'Issue.count' do
588 606 post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
589 607 assert_response :created
590 608 end
591 609 issue = Issue.order('id DESC').first
592 610 assert_equal 2, issue.attachments.count
593 611 end
594 612
595 613 def test_create_issue_with_multiple_uploaded_files_as_json
596 614 token1 = json_upload('File content 1', credentials('jsmith'))
597 615 token2 = json_upload('File content 2', credentials('jsmith'))
598 616
599 617 payload = <<-JSON
600 618 {
601 619 "issue": {
602 620 "project_id": "1",
603 621 "tracker_id": "1",
604 622 "subject": "Issue with multiple attachments",
605 623 "uploads": [
606 624 {"token": "#{token1}", "filename": "test1.txt"},
607 625 {"token": "#{token2}", "filename": "test2.txt"}
608 626 ]
609 627 }
610 628 }
611 629 JSON
612 630
613 631 assert_difference 'Issue.count' do
614 632 post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
615 633 assert_response :created
616 634 end
617 635 issue = Issue.order('id DESC').first
618 636 assert_equal 2, issue.attachments.count
619 637 end
620 638
621 639 def test_update_issue_with_uploaded_file
622 640 set_tmp_attachments_directory
623 641 # upload the file
624 642 assert_difference 'Attachment.count' do
625 643 post '/uploads.xml', 'test_upload_with_upload',
626 644 {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
627 645 assert_response :created
628 646 end
629 647 xml = Hash.from_xml(response.body)
630 648 token = xml['upload']['token']
631 649 attachment = Attachment.order('id DESC').first
632 650
633 651 # update the issue with the upload's token
634 652 assert_difference 'Journal.count' do
635 653 put '/issues/1.xml',
636 654 {:issue => {:notes => 'Attachment added',
637 655 :uploads => [{:token => token, :filename => 'test.txt',
638 656 :content_type => 'text/plain'}]}},
639 657 credentials('jsmith')
640 658 assert_response :ok
641 659 assert_equal '', @response.body
642 660 end
643 661
644 662 issue = Issue.find(1)
645 663 assert_include attachment, issue.attachments
646 664 end
647 665 end
General Comments 0
You need to be logged in to leave comments. Login now