##// END OF EJS Templates
Adds assertions on response status and body....
Jean-Philippe Lang -
r9793:54d55a360a21
parent child
Show More
@@ -625,54 +625,33 class ApiTest::IssuesTest < ActionController::IntegrationTest
625 {:issue => {:subject => 'API update', :notes => 'A new note'}},
625 {:issue => {:subject => 'API update', :notes => 'A new note'}},
626 {:success_code => :ok})
626 {:success_code => :ok})
627
627
628 should "not create a new issue" do
628 should "update the issue" do
629 assert_no_difference('Issue.count') do
629 assert_no_difference('Issue.count') do
630 put '/issues/6.json', @parameters, credentials('jsmith')
631 end
632 end
633
634 should "create a new journal" do
635 assert_difference('Journal.count') do
630 assert_difference('Journal.count') do
636 put '/issues/6.json', @parameters, credentials('jsmith')
631 put '/issues/6.json', @parameters, credentials('jsmith')
637 end
638 end
639
632
640 should "add the note to the journal" do
633 assert_response :ok
641 put '/issues/6.json', @parameters, credentials('jsmith')
634 assert_equal '', response.body
642
635 end
643 journal = Journal.last
644 assert_equal "A new note", journal.notes
645 end
636 end
646
647 should "update the issue" do
648 put '/issues/6.json', @parameters, credentials('jsmith')
649
637
650 issue = Issue.find(6)
638 issue = Issue.find(6)
651 assert_equal "API update", issue.subject
639 assert_equal "API update", issue.subject
640 journal = Journal.last
641 assert_equal "A new note", journal.notes
652 end
642 end
653
654 end
643 end
655
644
656 context "PUT /issues/6.json with failed update" do
645 context "PUT /issues/6.json with failed update" do
657 setup do
646 should "return errors" do
658 @parameters = {:issue => {:subject => ''}}
659 end
660
661 should "not create a new issue" do
662 assert_no_difference('Issue.count') do
647 assert_no_difference('Issue.count') do
663 put '/issues/6.json', @parameters, credentials('jsmith')
664 end
665 end
666
667 should "not create a new journal" do
668 assert_no_difference('Journal.count') do
648 assert_no_difference('Journal.count') do
669 put '/issues/6.json', @parameters, credentials('jsmith')
649 put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
650
651 assert_response :unprocessable_entity
670 end
652 end
671 end
653 end
672
654
673 should "have an errors attribute" do
674 put '/issues/6.json', @parameters, credentials('jsmith')
675
676 json = ActiveSupport::JSON.decode(response.body)
655 json = ActiveSupport::JSON.decode(response.body)
677 assert json['errors'].include?("Subject can't be blank")
656 assert json['errors'].include?("Subject can't be blank")
678 end
657 end
@@ -687,6 +666,9 class ApiTest::IssuesTest < ActionController::IntegrationTest
687 should "delete the issue" do
666 should "delete the issue" do
688 assert_difference('Issue.count',-1) do
667 assert_difference('Issue.count', -1) do
689 delete '/issues/6.xml', {}, credentials('jsmith')
668 delete '/issues/6.xml', {}, credentials('jsmith')
669
670 assert_response :ok
671 assert_equal '', response.body
690 end
672 end
691
673
692 assert_nil Issue.find_by_id(6)
674 assert_nil Issue.find_by_id(6)
@@ -702,6 +684,9 class ApiTest::IssuesTest < ActionController::IntegrationTest
702 should "delete the issue" do
684 should "delete the issue" do
703 assert_difference('Issue.count',-1) do
685 assert_difference('Issue.count', -1) do
704 delete '/issues/6.json', {}, credentials('jsmith')
686 delete '/issues/6.json', {}, credentials('jsmith')
687
688 assert_response :ok
689 assert_equal '', response.body
705 end
690 end
706
691
707 assert_nil Issue.find_by_id(6)
692 assert_nil Issue.find_by_id(6)
General Comments 0
You need to be logged in to leave comments. Login now