aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
authorJorge Bejar <jorge@wyeworks.com>2015-07-06 21:33:19 -0300
committerJorge Bejar <jorge@wyeworks.com>2015-12-09 10:53:41 -0300
commit83b4e9073f0852afc065ef398bd3ad9b5a6db29c (patch)
treedc2f2e814f8c6dcf4a1a0768c58c99e6d295d302 /actionpack/test/dispatch
parentb79bfaadaf5b5c6d3e458c24184a0e846bd8cf55 (diff)
downloadrails-83b4e9073f0852afc065ef398bd3ad9b5a6db29c.tar.gz
rails-83b4e9073f0852afc065ef398bd3ad9b5a6db29c.tar.bz2
rails-83b4e9073f0852afc065ef398bd3ad9b5a6db29c.zip
Response when error should be formatted properly in Rails API if local request
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/debug_exceptions_test.rb18
-rw-r--r--actionpack/test/dispatch/routing_test.rb1
2 files changed, 19 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb
index 30772bd9ed..48eff700ce 100644
--- a/actionpack/test/dispatch/debug_exceptions_test.rb
+++ b/actionpack/test/dispatch/debug_exceptions_test.rb
@@ -75,6 +75,13 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
end
end
+ class BoomerAPI < Boomer
+ def call(env)
+ env['action_dispatch.show_detailed_exceptions'] = @detailed
+ raise "puke!"
+ end
+ end
+
RoutesApp = Struct.new(:routes).new(SharedTestRoutes)
ProductionApp = ActionDispatch::DebugExceptions.new(Boomer.new(false), RoutesApp)
DevelopmentApp = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp)
@@ -155,6 +162,17 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
assert_match(/ActionController::ParameterMissing/, body)
end
+ test "rescue with json on API request" do
+ @app = ActionDispatch::DebugExceptions.new(BoomerAPI.new(true), RoutesApp, true)
+
+ get "/index.json", headers: { 'action_dispatch.show_exceptions' => true }
+ assert_response 500
+ assert_no_match(/<header>/, body)
+ assert_no_match(/<body>/, body)
+ assert_equal "application/json", response.content_type
+ assert_match(/RuntimeError: puke/, body)
+ end
+
test "rescue with text error for xhr request" do
@app = DevelopmentApp
xhr_request_env = {'action_dispatch.show_exceptions' => true, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'}
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 8972f3e74d..1b711e1bf8 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -3272,6 +3272,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
expected_params = {
controller: 'downloads',
action: 'show',
+ format: 'tar',
id: '1'
}