diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2015-04-16 15:56:07 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2015-06-11 16:54:10 -0300 |
commit | 3adb5eac3b6d81a0943bebd8dffa25a3b63681eb (patch) | |
tree | 5343cc59c6765d1a0b83a74710a347d376e3d666 /actionpack/test | |
parent | 212a099ab022fe617d94f195423432dad5cdb21a (diff) | |
download | rails-3adb5eac3b6d81a0943bebd8dffa25a3b63681eb.tar.gz rails-3adb5eac3b6d81a0943bebd8dffa25a3b63681eb.tar.bz2 rails-3adb5eac3b6d81a0943bebd8dffa25a3b63681eb.zip |
Add ApiPublicException middleware
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/show_exceptions_test.rb | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 72eaa916bc..c70bc5f95e 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -11,7 +11,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest when "/bad_params" raise ActionDispatch::ParamsParser::ParseError.new("", StandardError.new) when "/method_not_allowed" - raise ActionController::MethodNotAllowed + raise ActionController::MethodNotAllowed, 'PUT' when "/unknown_http_method" raise ActionController::UnknownHttpMethod when "/not_found_original_exception" @@ -22,7 +22,8 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest end end - ProductionApp = ActionDispatch::ShowExceptions.new(Boomer.new, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")) + ProductionApp = ActionDispatch::ShowExceptions.new(Boomer.new, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")) + ProductionApiApp = ActionDispatch::ShowExceptions.new(Boomer.new, ActionDispatch::ApiPublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")) test "skip exceptions app if not showing exceptions" do @app = ProductionApp @@ -55,6 +56,42 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest assert_equal "", body end + test "rescue api apps with json response" do + @app = ProductionApiApp + + get "/", headers: { 'HTTP_ACCEPT' => 'application/json', 'action_dispatch.show_exceptions' => true } + assert_response 500 + assert_equal({ :status => '500', :error => 'puke!' }.to_json, body) + + get "/method_not_allowed", headers: { 'HTTP_ACCEPT' => 'application/json', 'action_dispatch.show_exceptions' => true } + assert_response 405 + assert_equal({ :status => '405', :error => 'Only PUT requests are allowed.' }.to_json, body) + + get "/unknown_http_method", headers: { 'HTTP_ACCEPT' => 'application/json', 'action_dispatch.show_exceptions' => true } + assert_response 405 + assert_equal({ :status => '405', :error => 'ActionController::UnknownHttpMethod' }.to_json, body) + end + + test "rescue api apps unknown content-type requests with html response" do + @app = ProductionApiApp + + get "/", headers: { 'HTTP_ACCEPT' => 'application/x-custom', 'action_dispatch.show_exceptions' => true } + assert_response 500 + assert_equal "500 error fixture\n", body + + get "/bad_params", headers: { 'HTTP_ACCEPT' => 'application/x-custom', 'action_dispatch.show_exceptions' => true } + assert_response 400 + assert_equal "400 error fixture\n", body + + get "/not_found", headers: { 'HTTP_ACCEPT' => 'application/x-custom', 'action_dispatch.show_exceptions' => true } + assert_response 404 + assert_equal "404 error fixture\n", body + + get "/unknown_http_method", headers: { 'HTTP_ACCEPT' => 'application/x-custom', 'action_dispatch.show_exceptions' => true } + assert_response 405 + assert_equal("", body) + end + test "localize rescue error page" do old_locale, I18n.locale = I18n.locale, :da |