From 5e3517ea7b9fbd460f772bffc9212d882011f2bc Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 4 Oct 2008 18:43:46 +0100 Subject: Ensure rescue_from handlers are respected inside tests. [#835 state:resolved] Note : If you're not using rescue_from, you should overrider rescue_action_without_handler() method and not rescue_action(). Afterwards, you can set request.remote_addr to a non "0.0.0.0" value for testing the overridden behavior. --- actionpack/lib/action_controller/rescue.rb | 36 +++++++++++++-------------- actionpack/lib/action_controller/test_case.rb | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/rescue.rb b/actionpack/lib/action_controller/rescue.rb index 83c4218af4..0e0fe15fdb 100644 --- a/actionpack/lib/action_controller/rescue.rb +++ b/actionpack/lib/action_controller/rescue.rb @@ -112,24 +112,7 @@ module ActionController #:nodoc: protected # Exception handler called when the performance of an action raises an exception. def rescue_action(exception) - if handler_for_rescue(exception) - rescue_action_with_handler(exception) - else - log_error(exception) if logger - erase_results if performed? - - # Let the exception alter the response if it wants. - # For example, MethodNotAllowed sets the Allow header. - if exception.respond_to?(:handle_response!) - exception.handle_response!(response) - end - - if consider_all_requests_local || local_request? - rescue_action_locally(exception) - else - rescue_action_in_public(exception) - end - end + rescue_action_with_handler(exception) || rescue_action_without_handler(exception) end # Overwrite to implement custom logging of errors. By default logs as fatal. @@ -197,6 +180,23 @@ module ActionController #:nodoc: end end + def rescue_action_without_handler(exception) + log_error(exception) if logger + erase_results if performed? + + # Let the exception alter the response if it wants. + # For example, MethodNotAllowed sets the Allow header. + if exception.respond_to?(:handle_response!) + exception.handle_response!(response) + end + + if consider_all_requests_local || local_request? + rescue_action_locally(exception) + else + rescue_action_in_public(exception) + end + end + private def perform_action_with_rescue #:nodoc: perform_action_without_rescue diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 3e66947d5f..6a39039504 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -84,7 +84,7 @@ module ActionController module RaiseActionExceptions attr_accessor :exception - def rescue_action(e) + def rescue_action_without_handler(e) self.exception = e if request.remote_addr == "0.0.0.0" -- cgit v1.2.3