Permalink
Browse files

Added ActionController::TestCase#rescue_action_in_public! to control …

…whether the action under test should use the regular rescue_action path instead of simply raising the exception inline (great for error testing) [DHH]
  • Loading branch information...
1 parent 027f0f8 commit dc2d6930145ac80affb12bebf0fede21792755cf David Heinemeier Hansson committed Apr 28, 2008
Showing with 23 additions and 2 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +21 −2 actionpack/lib/action_controller/test_case.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Added ActionController::TestCase#rescue_action_in_public! to control whether the action under test should use the regular rescue_action path instead of simply raising the exception inline (great for error testing) [DHH]
+
* Reduce number of instance variables being copied from controller to view. [Pratik]
* select_datetime and select_time default to Time.zone.now when config.time_zone is set [Geoff Buesing]
@@ -16,9 +16,23 @@ def inferred_controller_name
end
class TestCase < ActiveSupport::TestCase
+ # When the request.remote_addr remains the default for testing, which is 0.0.0.0, the exception is simply raised inline
+ # (bystepping the regular exception handling from rescue_action). If the request.remote_addr is anything else, the regular
+ # rescue_action process takes place. This means you can test your rescue_action code by setting remote_addr to something else
+ # than 0.0.0.0.
+ #
+ # The exception is stored in the exception accessor for further inspection.
module RaiseActionExceptions
+ attr_accessor :exception
+
def rescue_action(e)
- raise e
+ self.exception = e
+
+ if request.remote_addr == "0.0.0.0"
+ raise(e)
+ else
+ super(e)
+ end
end
end
@@ -60,5 +74,10 @@ def setup_controller_request_and_response
@controller.request = @request = TestRequest.new
@response = TestResponse.new
end
+
+ # Cause the action to be rescued according to the regular rules for rescue_action when the visitor is not local
+ def rescue_action_in_public!
+ @request.remote_addr = '208.77.188.166' # example.com
+ end
end
-end
+end

0 comments on commit dc2d693

Please sign in to comment.