aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/debug_exceptions_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/dispatch/debug_exceptions_test.rb')
-rw-r--r--actionpack/test/dispatch/debug_exceptions_test.rb45
1 files changed, 43 insertions, 2 deletions
diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb
index e6c0a06878..f3dc160d7d 100644
--- a/actionpack/test/dispatch/debug_exceptions_test.rb
+++ b/actionpack/test/dispatch/debug_exceptions_test.rb
@@ -3,14 +3,26 @@ require 'abstract_unit'
class DebugExceptionsTest < ActionDispatch::IntegrationTest
class Boomer
+ attr_accessor :closed
+
def initialize(detailed = false)
@detailed = detailed
+ @closed = false
+ end
+
+ def each
+ end
+
+ def close
+ @closed = true
end
def call(env)
env['action_dispatch.show_detailed_exceptions'] = @detailed
req = ActionDispatch::Request.new(env)
case req.path
+ when "/pass"
+ [404, { "X-Cascade" => "pass" }, self]
when "/not_found"
raise ActionController::UnknownAction
when "/runtime_error"
@@ -29,8 +41,8 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
end
end
- ProductionApp = ActionDispatch::DebugExceptions.new((Boomer.new(false)))
- DevelopmentApp = ActionDispatch::DebugExceptions.new((Boomer.new(true)))
+ ProductionApp = ActionDispatch::DebugExceptions.new(Boomer.new(false))
+ DevelopmentApp = ActionDispatch::DebugExceptions.new(Boomer.new(true))
test 'skip diagnosis if not showing detailed exceptions' do
@app = ProductionApp
@@ -46,6 +58,22 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
end
end
+ test 'raise an exception on cascade pass' do
+ @app = ProductionApp
+ assert_raise ActionController::RoutingError do
+ get "/pass", {}, {'action_dispatch.show_exceptions' => true}
+ end
+ end
+
+ test 'closes the response body on cascade pass' do
+ boomer = Boomer.new(false)
+ @app = ActionDispatch::DebugExceptions.new(boomer)
+ assert_raise ActionController::RoutingError do
+ get "/pass", {}, {'action_dispatch.show_exceptions' => true}
+ end
+ assert boomer.closed, "Expected to close the response body"
+ end
+
test "rescue with diagnostics message" do
@app = DevelopmentApp
@@ -113,4 +141,17 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
get "/", {}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.backtrace_cleaner' => cleaner}
assert_match(/passed backtrace cleaner/, body)
end
+
+ test 'logs exception backtrace when all lines silenced' do
+ output = StringIO.new
+ backtrace_cleaner = ActiveSupport::BacktraceCleaner.new
+ backtrace_cleaner.add_silencer { true }
+
+ env = {'action_dispatch.show_exceptions' => true,
+ 'action_dispatch.logger' => Logger.new(output),
+ 'action_dispatch.backtrace_cleaner' => backtrace_cleaner}
+
+ get "/", {}, env
+ assert_operator((output.rewind && output.read).lines.count, :>, 10)
+ end
end