aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@envy8.local>2008-04-27 19:42:13 -0500
committerDavid Heinemeier Hansson <david@envy8.local>2008-04-27 19:42:13 -0500
commitdc2d6930145ac80affb12bebf0fede21792755cf (patch)
treeddc784ad711897d46de20210a7c175830e1a5a58 /actionpack
parent027f0f822f418aba41f1d52f9d5895e34fae0310 (diff)
downloadrails-dc2d6930145ac80affb12bebf0fede21792755cf.tar.gz
rails-dc2d6930145ac80affb12bebf0fede21792755cf.tar.bz2
rails-dc2d6930145ac80affb12bebf0fede21792755cf.zip
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]
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/test_case.rb23
2 files changed, 23 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 5a2122b64b..65a5934bba 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -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]
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 06b12a524f..77c6f26eac 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -16,9 +16,23 @@ module ActionController
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 @@ module ActionController
@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 \ No newline at end of file