diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2015-12-09 15:26:46 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2015-12-09 15:26:46 -0300 |
commit | b11bca98bf5431ce9522c6b5707f51cd8d7f401c (patch) | |
tree | f665325e17cb88cdc8b8ae3ef8750806a02ed0c3 /actionpack/test/dispatch/show_exceptions_test.rb | |
parent | b05801754f6423a1d90954ef3f6e2f5dc55c6320 (diff) | |
parent | cdb7a8477ff19f8ed6f549cedc901bd5934a61e8 (diff) | |
download | rails-b11bca98bf5431ce9522c6b5707f51cd8d7f401c.tar.gz rails-b11bca98bf5431ce9522c6b5707f51cd8d7f401c.tar.bz2 rails-b11bca98bf5431ce9522c6b5707f51cd8d7f401c.zip |
Merge pull request #20831 from jmbejar/rails-api-json-error-response
Rails API: Ability to return error responses in json format also in development
Diffstat (limited to 'actionpack/test/dispatch/show_exceptions_test.rb')
-rw-r--r-- | actionpack/test/dispatch/show_exceptions_test.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index ffdf775836..14894d4b82 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -8,7 +8,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest case req.path when "/not_found" raise AbstractController::ActionNotFound - when "/bad_params" + when "/bad_params", "/bad_params.json" begin raise StandardError.new rescue @@ -120,4 +120,18 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest assert_response 405 assert_equal "", body end + + test "bad params exception is returned in the correct format" do + @app = ProductionApp + + get "/bad_params", headers: { 'action_dispatch.show_exceptions' => true } + assert_equal "text/html; charset=utf-8", response.headers["Content-Type"] + assert_response 400 + assert_match(/400 error/, body) + + get "/bad_params.json", headers: { 'action_dispatch.show_exceptions' => true } + assert_equal "application/json; charset=utf-8", response.headers["Content-Type"] + assert_response 400 + assert_equal("{\"status\":400,\"error\":\"Bad Request\"}", body) + end end |