aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorDenis Odorcic <denis.odorcic@jadedpixel.com>2011-10-10 01:42:12 -0400
committerDenis Odorcic <denis.odorcic@jadedpixel.com>2011-10-10 01:42:12 -0400
commita0a68ecbb22dacf5111198e72e3a803e7c965881 (patch)
treed96fc951fa27c3730e28ad28607cf5223f0e5c64 /actionpack/test
parent3456ef11196406f4ae6908d89ec66d38dc716738 (diff)
downloadrails-a0a68ecbb22dacf5111198e72e3a803e7c965881.tar.gz
rails-a0a68ecbb22dacf5111198e72e3a803e7c965881.tar.bz2
rails-a0a68ecbb22dacf5111198e72e3a803e7c965881.zip
JSON responder should return errors with :error root
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/mime_responds_test.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index afb2d39955..afdab30eaf 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -745,6 +745,20 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
+ def test_using_resource_for_post_with_json_yields_unprocessable_entity_on_failure
+ with_test_route_set do
+ @request.accept = "application/json"
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ post :using_resource
+ assert_equal "application/json", @response.content_type
+ assert_equal 422, @response.status
+ errors = {:errors => errors}
+ assert_equal errors.to_json, @response.body
+ assert_nil @response.location
+ end
+ end
+
def test_using_resource_for_put_with_html_redirects_on_success
with_test_route_set do
put :using_resource
@@ -808,6 +822,18 @@ class RespondWithControllerTest < ActionController::TestCase
assert_nil @response.location
end
+ def test_using_resource_for_put_with_json_yields_unprocessable_entity_on_failure
+ @request.accept = "application/json"
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ put :using_resource
+ assert_equal "application/json", @response.content_type
+ assert_equal 422, @response.status
+ errors = {:errors => errors}
+ assert_equal errors.to_json, @response.body
+ assert_nil @response.location
+ end
+
def test_using_resource_for_delete_with_html_redirects_on_success
with_test_route_set do
Customer.any_instance.stubs(:destroyed?).returns(true)