##// END OF EJS Templates
Adds assertions on response status and body....
Jean-Philippe Lang -
r9793:54d55a360a21
parent child
Show More
@@ -625,53 +625,32 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')
630 assert_difference('Journal.count') do
631 end
631 put '/issues/6.json', @parameters, credentials('jsmith')
632 end
633
632
634 should "create a new journal" do
633 assert_response :ok
635 assert_difference('Journal.count') do
634 assert_equal '', response.body
636 put '/issues/6.json', @parameters, credentials('jsmith')
635 end
637 end
636 end
638 end
639
640 should "add the note to the journal" do
641 put '/issues/6.json', @parameters, credentials('jsmith')
642
643 journal = Journal.last
644 assert_equal "A new note", journal.notes
645 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')
648 assert_no_difference('Journal.count') do
664 end
649 put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
665 end
666
650
667 should "not create a new journal" do
651 assert_response :unprocessable_entity
668 assert_no_difference('Journal.count') do
652 end
669 put '/issues/6.json', @parameters, credentials('jsmith')
670 end
653 end
671 end
672
673 should "have an errors attribute" do
674 put '/issues/6.json', @parameters, credentials('jsmith')
675
654
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")
@@ -685,8 +664,11 class ApiTest::IssuesTest < ActionController::IntegrationTest
685 {:success_code => :ok})
664 {:success_code => :ok})
686
665
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)
@@ -700,8 +682,11 class ApiTest::IssuesTest < ActionController::IntegrationTest
700 {:success_code => :ok})
682 {:success_code => :ok})
701
683
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