Mercurial > hg > soundsoftware-site
comparison test/integration/api_test/issues_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 261b3d9a4903 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
23 :roles, | 23 :roles, |
24 :members, | 24 :members, |
25 :member_roles, | 25 :member_roles, |
26 :issues, | 26 :issues, |
27 :issue_statuses, | 27 :issue_statuses, |
28 :issue_relations, | |
28 :versions, | 29 :versions, |
29 :trackers, | 30 :trackers, |
30 :projects_trackers, | 31 :projects_trackers, |
31 :issue_categories, | 32 :issue_categories, |
32 :enabled_modules, | 33 :enabled_modules, |
111 assert_tag 'relations', | 112 assert_tag 'relations', |
112 :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '3'}}, | 113 :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '3'}}, |
113 :children => {:count => 1}, | 114 :children => {:count => 1}, |
114 :child => { | 115 :child => { |
115 :tag => 'relation', | 116 :tag => 'relation', |
116 :attributes => {:id => '2', :issue_id => '2', :issue_to_id => '3', :relation_type => 'relates'} | 117 :attributes => {:id => '2', :issue_id => '2', :issue_to_id => '3', |
118 :relation_type => 'relates'} | |
117 } | 119 } |
118 assert_tag 'relations', | 120 assert_tag 'relations', |
119 :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '1'}}, | 121 :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '1'}}, |
120 :children => {:count => 0} | 122 :children => {:count => 0} |
121 end | 123 end |
131 end | 133 end |
132 end | 134 end |
133 | 135 |
134 context "with custom field filter" do | 136 context "with custom field filter" do |
135 should "show only issues with the custom field value" do | 137 should "show only issues with the custom field value" do |
136 get '/issues.xml', { :set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}} | 138 get '/issues.xml', |
137 | 139 {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, |
140 :v => {:cf_1 => ['MySQL']}} | |
138 expected_ids = Issue.visible.all( | 141 expected_ids = Issue.visible.all( |
139 :include => :custom_values, | 142 :include => :custom_values, |
140 :conditions => {:custom_values => {:custom_field_id => 1, :value => 'MySQL'}}).map(&:id) | 143 :conditions => {:custom_values => {:custom_field_id => 1, :value => 'MySQL'}}).map(&:id) |
141 | |
142 assert_select 'issues > issue > id', :count => expected_ids.count do |ids| | 144 assert_select 'issues > issue > id', :count => expected_ids.count do |ids| |
143 ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } | 145 ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } |
144 end | 146 end |
145 end | 147 end |
146 end | 148 end |
256 end | 258 end |
257 end | 259 end |
258 end | 260 end |
259 end | 261 end |
260 | 262 |
263 context "with multi custom fields" do | |
264 setup do | |
265 field = CustomField.find(1) | |
266 field.update_attribute :multiple, true | |
267 issue = Issue.find(3) | |
268 issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
269 issue.save! | |
270 end | |
271 | |
272 context ".xml" do | |
273 should "display custom fields" do | |
274 get '/issues/3.xml' | |
275 assert_response :success | |
276 assert_tag :tag => 'issue', | |
277 :child => { | |
278 :tag => 'custom_fields', | |
279 :attributes => { :type => 'array' }, | |
280 :child => { | |
281 :tag => 'custom_field', | |
282 :attributes => { :id => '1'}, | |
283 :child => { | |
284 :tag => 'value', | |
285 :attributes => { :type => 'array' }, | |
286 :children => { :count => 2 } | |
287 } | |
288 } | |
289 } | |
290 | |
291 xml = Hash.from_xml(response.body) | |
292 custom_fields = xml['issue']['custom_fields'] | |
293 assert_kind_of Array, custom_fields | |
294 field = custom_fields.detect {|f| f['id'] == '1'} | |
295 assert_kind_of Hash, field | |
296 assert_equal ['MySQL', 'Oracle'], field['value'].sort | |
297 end | |
298 end | |
299 | |
300 context ".json" do | |
301 should "display custom fields" do | |
302 get '/issues/3.json' | |
303 assert_response :success | |
304 json = ActiveSupport::JSON.decode(response.body) | |
305 custom_fields = json['issue']['custom_fields'] | |
306 assert_kind_of Array, custom_fields | |
307 field = custom_fields.detect {|f| f['id'] == 1} | |
308 assert_kind_of Hash, field | |
309 assert_equal ['MySQL', 'Oracle'], field['value'].sort | |
310 end | |
311 end | |
312 end | |
313 | |
314 context "with empty value for multi custom field" do | |
315 setup do | |
316 field = CustomField.find(1) | |
317 field.update_attribute :multiple, true | |
318 issue = Issue.find(3) | |
319 issue.custom_field_values = {1 => ['']} | |
320 issue.save! | |
321 end | |
322 | |
323 context ".xml" do | |
324 should "display custom fields" do | |
325 get '/issues/3.xml' | |
326 assert_response :success | |
327 assert_tag :tag => 'issue', | |
328 :child => { | |
329 :tag => 'custom_fields', | |
330 :attributes => { :type => 'array' }, | |
331 :child => { | |
332 :tag => 'custom_field', | |
333 :attributes => { :id => '1'}, | |
334 :child => { | |
335 :tag => 'value', | |
336 :attributes => { :type => 'array' }, | |
337 :children => { :count => 0 } | |
338 } | |
339 } | |
340 } | |
341 | |
342 xml = Hash.from_xml(response.body) | |
343 custom_fields = xml['issue']['custom_fields'] | |
344 assert_kind_of Array, custom_fields | |
345 field = custom_fields.detect {|f| f['id'] == '1'} | |
346 assert_kind_of Hash, field | |
347 assert_equal [], field['value'] | |
348 end | |
349 end | |
350 | |
351 context ".json" do | |
352 should "display custom fields" do | |
353 get '/issues/3.json' | |
354 assert_response :success | |
355 json = ActiveSupport::JSON.decode(response.body) | |
356 custom_fields = json['issue']['custom_fields'] | |
357 assert_kind_of Array, custom_fields | |
358 field = custom_fields.detect {|f| f['id'] == 1} | |
359 assert_kind_of Hash, field | |
360 assert_equal [], field['value'].sort | |
361 end | |
362 end | |
363 end | |
364 | |
261 context "with attachments" do | 365 context "with attachments" do |
262 context ".xml" do | 366 context ".xml" do |
263 should "display attachments" do | 367 should "display attachments" do |
264 get '/issues/3.xml?include=attachments' | 368 get '/issues/3.xml?include=attachments' |
265 | 369 |
283 end | 387 end |
284 end | 388 end |
285 | 389 |
286 context "with subtasks" do | 390 context "with subtasks" do |
287 setup do | 391 setup do |
288 @c1 = Issue.generate!(:status_id => 1, :subject => "child c1", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1) | 392 @c1 = Issue.create!( |
289 @c2 = Issue.generate!(:status_id => 1, :subject => "child c2", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1) | 393 :status_id => 1, :subject => "child c1", |
290 @c3 = Issue.generate!(:status_id => 1, :subject => "child c3", :tracker_id => 1, :project_id => 1, :parent_issue_id => @c1.id) | 394 :tracker_id => 1, :project_id => 1, :author_id => 1, |
395 :parent_issue_id => 1 | |
396 ) | |
397 @c2 = Issue.create!( | |
398 :status_id => 1, :subject => "child c2", | |
399 :tracker_id => 1, :project_id => 1, :author_id => 1, | |
400 :parent_issue_id => 1 | |
401 ) | |
402 @c3 = Issue.create!( | |
403 :status_id => 1, :subject => "child c3", | |
404 :tracker_id => 1, :project_id => 1, :author_id => 1, | |
405 :parent_issue_id => @c1.id | |
406 ) | |
291 end | 407 end |
292 | 408 |
293 context ".xml" do | 409 context ".xml" do |
294 should "display children" do | 410 should "display children" do |
295 get '/issues/1.xml?include=children' | 411 get '/issues/1.xml?include=children' |
323 | 439 |
324 json = ActiveSupport::JSON.decode(response.body) | 440 json = ActiveSupport::JSON.decode(response.body) |
325 assert_equal([ | 441 assert_equal([ |
326 { | 442 { |
327 'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'}, | 443 'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'}, |
328 'children' => [{ 'id' => @c3.id, 'subject' => 'child c3', 'tracker' => {'id' => 1, 'name' => 'Bug'} }] | 444 'children' => [{'id' => @c3.id, 'subject' => 'child c3', |
445 'tracker' => {'id' => 1, 'name' => 'Bug'} }] | |
329 }, | 446 }, |
330 { 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} } | 447 { 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} } |
331 ], | 448 ], |
332 json['issue']['children']) | 449 json['issue']['children']) |
333 end | 450 end |
335 end | 452 end |
336 end | 453 end |
337 end | 454 end |
338 | 455 |
339 context "POST /issues.xml" do | 456 context "POST /issues.xml" do |
340 should_allow_api_authentication(:post, | 457 should_allow_api_authentication( |
341 '/issues.xml', | 458 :post, |
342 {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, | 459 '/issues.xml', |
343 {:success_code => :created}) | 460 {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, |
344 | 461 {:success_code => :created} |
462 ) | |
345 should "create an issue with the attributes" do | 463 should "create an issue with the attributes" do |
346 assert_difference('Issue.count') do | 464 assert_difference('Issue.count') do |
347 post '/issues.xml', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, :authorization => credentials('jsmith') | 465 post '/issues.xml', |
348 end | 466 {:issue => {:project_id => 1, :subject => 'API test', |
349 | 467 :tracker_id => 2, :status_id => 3}}, credentials('jsmith') |
468 end | |
350 issue = Issue.first(:order => 'id DESC') | 469 issue = Issue.first(:order => 'id DESC') |
351 assert_equal 1, issue.project_id | 470 assert_equal 1, issue.project_id |
352 assert_equal 2, issue.tracker_id | 471 assert_equal 2, issue.tracker_id |
353 assert_equal 3, issue.status_id | 472 assert_equal 3, issue.status_id |
354 assert_equal 'API test', issue.subject | 473 assert_equal 'API test', issue.subject |
360 end | 479 end |
361 | 480 |
362 context "POST /issues.xml with failure" do | 481 context "POST /issues.xml with failure" do |
363 should "have an errors tag" do | 482 should "have an errors tag" do |
364 assert_no_difference('Issue.count') do | 483 assert_no_difference('Issue.count') do |
365 post '/issues.xml', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith') | 484 post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith') |
366 end | 485 end |
367 | 486 |
368 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} | 487 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} |
369 end | 488 end |
370 end | 489 end |
371 | 490 |
372 context "POST /issues.json" do | 491 context "POST /issues.json" do |
373 should_allow_api_authentication(:post, | 492 should_allow_api_authentication(:post, |
374 '/issues.json', | 493 '/issues.json', |
375 {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, | 494 {:issue => {:project_id => 1, :subject => 'API test', |
495 :tracker_id => 2, :status_id => 3}}, | |
376 {:success_code => :created}) | 496 {:success_code => :created}) |
377 | 497 |
378 should "create an issue with the attributes" do | 498 should "create an issue with the attributes" do |
379 assert_difference('Issue.count') do | 499 assert_difference('Issue.count') do |
380 post '/issues.json', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, :authorization => credentials('jsmith') | 500 post '/issues.json', |
501 {:issue => {:project_id => 1, :subject => 'API test', | |
502 :tracker_id => 2, :status_id => 3}}, | |
503 credentials('jsmith') | |
381 end | 504 end |
382 | 505 |
383 issue = Issue.first(:order => 'id DESC') | 506 issue = Issue.first(:order => 'id DESC') |
384 assert_equal 1, issue.project_id | 507 assert_equal 1, issue.project_id |
385 assert_equal 2, issue.tracker_id | 508 assert_equal 2, issue.tracker_id |
390 end | 513 end |
391 | 514 |
392 context "POST /issues.json with failure" do | 515 context "POST /issues.json with failure" do |
393 should "have an errors element" do | 516 should "have an errors element" do |
394 assert_no_difference('Issue.count') do | 517 assert_no_difference('Issue.count') do |
395 post '/issues.json', {:issue => {:project_id => 1}}, :authorization => credentials('jsmith') | 518 post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith') |
396 end | 519 end |
397 | 520 |
398 json = ActiveSupport::JSON.decode(response.body) | 521 json = ActiveSupport::JSON.decode(response.body) |
399 assert json['errors'].include?(['subject', "can't be blank"]) | 522 assert json['errors'].include?("Subject can't be blank") |
400 end | 523 end |
401 end | 524 end |
402 | 525 |
403 # Issue 6 is on a private project | 526 # Issue 6 is on a private project |
404 context "PUT /issues/6.xml" do | 527 context "PUT /issues/6.xml" do |
405 setup do | 528 setup do |
406 @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} | 529 @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} |
407 @headers = { :authorization => credentials('jsmith') } | |
408 end | 530 end |
409 | 531 |
410 should_allow_api_authentication(:put, | 532 should_allow_api_authentication(:put, |
411 '/issues/6.xml', | 533 '/issues/6.xml', |
412 {:issue => {:subject => 'API update', :notes => 'A new note'}}, | 534 {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
413 {:success_code => :ok}) | 535 {:success_code => :ok}) |
414 | 536 |
415 should "not create a new issue" do | 537 should "not create a new issue" do |
416 assert_no_difference('Issue.count') do | 538 assert_no_difference('Issue.count') do |
417 put '/issues/6.xml', @parameters, @headers | 539 put '/issues/6.xml', @parameters, credentials('jsmith') |
418 end | 540 end |
419 end | 541 end |
420 | 542 |
421 should "create a new journal" do | 543 should "create a new journal" do |
422 assert_difference('Journal.count') do | 544 assert_difference('Journal.count') do |
423 put '/issues/6.xml', @parameters, @headers | 545 put '/issues/6.xml', @parameters, credentials('jsmith') |
424 end | 546 end |
425 end | 547 end |
426 | 548 |
427 should "add the note to the journal" do | 549 should "add the note to the journal" do |
428 put '/issues/6.xml', @parameters, @headers | 550 put '/issues/6.xml', @parameters, credentials('jsmith') |
429 | 551 |
430 journal = Journal.last | 552 journal = Journal.last |
431 assert_equal "A new note", journal.notes | 553 assert_equal "A new note", journal.notes |
432 end | 554 end |
433 | 555 |
434 should "update the issue" do | 556 should "update the issue" do |
435 put '/issues/6.xml', @parameters, @headers | 557 put '/issues/6.xml', @parameters, credentials('jsmith') |
436 | 558 |
437 issue = Issue.find(6) | 559 issue = Issue.find(6) |
438 assert_equal "API update", issue.subject | 560 assert_equal "API update", issue.subject |
439 end | 561 end |
440 | 562 |
441 end | 563 end |
442 | 564 |
443 context "PUT /issues/3.xml with custom fields" do | 565 context "PUT /issues/3.xml with custom fields" do |
444 setup do | 566 setup do |
445 @parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}} | 567 @parameters = { |
446 @headers = { :authorization => credentials('jsmith') } | 568 :issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, |
569 {'id' => '2', 'value' => '150'}]} | |
570 } | |
447 end | 571 end |
448 | 572 |
449 should "update custom fields" do | 573 should "update custom fields" do |
450 assert_no_difference('Issue.count') do | 574 assert_no_difference('Issue.count') do |
451 put '/issues/3.xml', @parameters, @headers | 575 put '/issues/3.xml', @parameters, credentials('jsmith') |
452 end | 576 end |
453 | 577 |
454 issue = Issue.find(3) | 578 issue = Issue.find(3) |
455 assert_equal '150', issue.custom_value_for(2).value | 579 assert_equal '150', issue.custom_value_for(2).value |
456 assert_equal 'PostgreSQL', issue.custom_value_for(1).value | 580 assert_equal 'PostgreSQL', issue.custom_value_for(1).value |
457 end | 581 end |
458 end | 582 end |
459 | 583 |
584 context "PUT /issues/3.xml with multi custom fields" do | |
585 setup do | |
586 field = CustomField.find(1) | |
587 field.update_attribute :multiple, true | |
588 @parameters = { | |
589 :issue => {:custom_fields => [{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, | |
590 {'id' => '2', 'value' => '150'}]} | |
591 } | |
592 end | |
593 | |
594 should "update custom fields" do | |
595 assert_no_difference('Issue.count') do | |
596 put '/issues/3.xml', @parameters, credentials('jsmith') | |
597 end | |
598 | |
599 issue = Issue.find(3) | |
600 assert_equal '150', issue.custom_value_for(2).value | |
601 assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort | |
602 end | |
603 end | |
604 | |
605 context "PUT /issues/3.xml with project change" do | |
606 setup do | |
607 @parameters = {:issue => {:project_id => 2, :subject => 'Project changed'}} | |
608 end | |
609 | |
610 should "update project" do | |
611 assert_no_difference('Issue.count') do | |
612 put '/issues/3.xml', @parameters, credentials('jsmith') | |
613 end | |
614 | |
615 issue = Issue.find(3) | |
616 assert_equal 2, issue.project_id | |
617 assert_equal 'Project changed', issue.subject | |
618 end | |
619 end | |
620 | |
460 context "PUT /issues/6.xml with failed update" do | 621 context "PUT /issues/6.xml with failed update" do |
461 setup do | 622 setup do |
462 @parameters = {:issue => {:subject => ''}} | 623 @parameters = {:issue => {:subject => ''}} |
463 @headers = { :authorization => credentials('jsmith') } | |
464 end | 624 end |
465 | 625 |
466 should "not create a new issue" do | 626 should "not create a new issue" do |
467 assert_no_difference('Issue.count') do | 627 assert_no_difference('Issue.count') do |
468 put '/issues/6.xml', @parameters, @headers | 628 put '/issues/6.xml', @parameters, credentials('jsmith') |
469 end | 629 end |
470 end | 630 end |
471 | 631 |
472 should "not create a new journal" do | 632 should "not create a new journal" do |
473 assert_no_difference('Journal.count') do | 633 assert_no_difference('Journal.count') do |
474 put '/issues/6.xml', @parameters, @headers | 634 put '/issues/6.xml', @parameters, credentials('jsmith') |
475 end | 635 end |
476 end | 636 end |
477 | 637 |
478 should "have an errors tag" do | 638 should "have an errors tag" do |
479 put '/issues/6.xml', @parameters, @headers | 639 put '/issues/6.xml', @parameters, credentials('jsmith') |
480 | 640 |
481 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} | 641 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} |
482 end | 642 end |
483 end | 643 end |
484 | 644 |
485 context "PUT /issues/6.json" do | 645 context "PUT /issues/6.json" do |
486 setup do | 646 setup do |
487 @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} | 647 @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} |
488 @headers = { :authorization => credentials('jsmith') } | |
489 end | 648 end |
490 | 649 |
491 should_allow_api_authentication(:put, | 650 should_allow_api_authentication(:put, |
492 '/issues/6.json', | 651 '/issues/6.json', |
493 {:issue => {:subject => 'API update', :notes => 'A new note'}}, | 652 {:issue => {:subject => 'API update', :notes => 'A new note'}}, |
494 {:success_code => :ok}) | 653 {:success_code => :ok}) |
495 | 654 |
496 should "not create a new issue" do | 655 should "update the issue" do |
497 assert_no_difference('Issue.count') do | 656 assert_no_difference('Issue.count') do |
498 put '/issues/6.json', @parameters, @headers | 657 assert_difference('Journal.count') do |
499 end | 658 put '/issues/6.json', @parameters, credentials('jsmith') |
500 end | 659 |
501 | 660 assert_response :ok |
502 should "create a new journal" do | 661 assert_equal '', response.body |
503 assert_difference('Journal.count') do | 662 end |
504 put '/issues/6.json', @parameters, @headers | 663 end |
505 end | 664 |
506 end | 665 issue = Issue.find(6) |
507 | 666 assert_equal "API update", issue.subject |
508 should "add the note to the journal" do | |
509 put '/issues/6.json', @parameters, @headers | |
510 | |
511 journal = Journal.last | 667 journal = Journal.last |
512 assert_equal "A new note", journal.notes | 668 assert_equal "A new note", journal.notes |
513 end | 669 end |
514 | |
515 should "update the issue" do | |
516 put '/issues/6.json', @parameters, @headers | |
517 | |
518 issue = Issue.find(6) | |
519 assert_equal "API update", issue.subject | |
520 end | |
521 | |
522 end | 670 end |
523 | 671 |
524 context "PUT /issues/6.json with failed update" do | 672 context "PUT /issues/6.json with failed update" do |
525 setup do | 673 should "return errors" do |
526 @parameters = {:issue => {:subject => ''}} | 674 assert_no_difference('Issue.count') do |
527 @headers = { :authorization => credentials('jsmith') } | 675 assert_no_difference('Journal.count') do |
528 end | 676 put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith') |
529 | 677 |
530 should "not create a new issue" do | 678 assert_response :unprocessable_entity |
531 assert_no_difference('Issue.count') do | 679 end |
532 put '/issues/6.json', @parameters, @headers | 680 end |
533 end | |
534 end | |
535 | |
536 should "not create a new journal" do | |
537 assert_no_difference('Journal.count') do | |
538 put '/issues/6.json', @parameters, @headers | |
539 end | |
540 end | |
541 | |
542 should "have an errors attribute" do | |
543 put '/issues/6.json', @parameters, @headers | |
544 | 681 |
545 json = ActiveSupport::JSON.decode(response.body) | 682 json = ActiveSupport::JSON.decode(response.body) |
546 assert json['errors'].include?(['subject', "can't be blank"]) | 683 assert json['errors'].include?("Subject can't be blank") |
547 end | 684 end |
548 end | 685 end |
549 | 686 |
550 context "DELETE /issues/1.xml" do | 687 context "DELETE /issues/1.xml" do |
551 should_allow_api_authentication(:delete, | 688 should_allow_api_authentication(:delete, |
552 '/issues/6.xml', | 689 '/issues/6.xml', |
553 {}, | 690 {}, |
554 {:success_code => :ok}) | 691 {:success_code => :ok}) |
555 | 692 |
556 should "delete the issue" do | 693 should "delete the issue" do |
557 assert_difference('Issue.count',-1) do | 694 assert_difference('Issue.count', -1) do |
558 delete '/issues/6.xml', {}, :authorization => credentials('jsmith') | 695 delete '/issues/6.xml', {}, credentials('jsmith') |
696 | |
697 assert_response :ok | |
698 assert_equal '', response.body | |
559 end | 699 end |
560 | 700 |
561 assert_nil Issue.find_by_id(6) | 701 assert_nil Issue.find_by_id(6) |
562 end | 702 end |
563 end | 703 end |
567 '/issues/6.json', | 707 '/issues/6.json', |
568 {}, | 708 {}, |
569 {:success_code => :ok}) | 709 {:success_code => :ok}) |
570 | 710 |
571 should "delete the issue" do | 711 should "delete the issue" do |
572 assert_difference('Issue.count',-1) do | 712 assert_difference('Issue.count', -1) do |
573 delete '/issues/6.json', {}, :authorization => credentials('jsmith') | 713 delete '/issues/6.json', {}, credentials('jsmith') |
714 | |
715 assert_response :ok | |
716 assert_equal '', response.body | |
574 end | 717 end |
575 | 718 |
576 assert_nil Issue.find_by_id(6) | 719 assert_nil Issue.find_by_id(6) |
577 end | 720 end |
578 end | 721 end |
579 | 722 |
580 def credentials(user, password=nil) | 723 def test_create_issue_with_uploaded_file |
581 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) | 724 set_tmp_attachments_directory |
725 # upload the file | |
726 assert_difference 'Attachment.count' do | |
727 post '/uploads.xml', 'test_create_with_upload', | |
728 {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) | |
729 assert_response :created | |
730 end | |
731 xml = Hash.from_xml(response.body) | |
732 token = xml['upload']['token'] | |
733 attachment = Attachment.first(:order => 'id DESC') | |
734 | |
735 # create the issue with the upload's token | |
736 assert_difference 'Issue.count' do | |
737 post '/issues.xml', | |
738 {:issue => {:project_id => 1, :subject => 'Uploaded file', | |
739 :uploads => [{:token => token, :filename => 'test.txt', | |
740 :content_type => 'text/plain'}]}}, | |
741 credentials('jsmith') | |
742 assert_response :created | |
743 end | |
744 issue = Issue.first(:order => 'id DESC') | |
745 assert_equal 1, issue.attachments.count | |
746 assert_equal attachment, issue.attachments.first | |
747 | |
748 attachment.reload | |
749 assert_equal 'test.txt', attachment.filename | |
750 assert_equal 'text/plain', attachment.content_type | |
751 assert_equal 'test_create_with_upload'.size, attachment.filesize | |
752 assert_equal 2, attachment.author_id | |
753 | |
754 # get the issue with its attachments | |
755 get "/issues/#{issue.id}.xml", :include => 'attachments' | |
756 assert_response :success | |
757 xml = Hash.from_xml(response.body) | |
758 attachments = xml['issue']['attachments'] | |
759 assert_kind_of Array, attachments | |
760 assert_equal 1, attachments.size | |
761 url = attachments.first['content_url'] | |
762 assert_not_nil url | |
763 | |
764 # download the attachment | |
765 get url | |
766 assert_response :success | |
767 end | |
768 | |
769 def test_update_issue_with_uploaded_file | |
770 set_tmp_attachments_directory | |
771 # upload the file | |
772 assert_difference 'Attachment.count' do | |
773 post '/uploads.xml', 'test_upload_with_upload', | |
774 {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) | |
775 assert_response :created | |
776 end | |
777 xml = Hash.from_xml(response.body) | |
778 token = xml['upload']['token'] | |
779 attachment = Attachment.first(:order => 'id DESC') | |
780 | |
781 # update the issue with the upload's token | |
782 assert_difference 'Journal.count' do | |
783 put '/issues/1.xml', | |
784 {:issue => {:notes => 'Attachment added', | |
785 :uploads => [{:token => token, :filename => 'test.txt', | |
786 :content_type => 'text/plain'}]}}, | |
787 credentials('jsmith') | |
788 assert_response :ok | |
789 assert_equal '', @response.body | |
790 end | |
791 | |
792 issue = Issue.find(1) | |
793 assert_include attachment, issue.attachments | |
582 end | 794 end |
583 end | 795 end |