aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-04-21 20:41:05 -0500
committerJoshua Peek <josh@joshpeek.com>2009-04-21 20:41:31 -0500
commit0b92bb97c185f426585af770dcf43b67b0253f50 (patch)
tree9b1fdd311acc45ab8bb306296473248e160e5855 /actionpack
parentfc5c1b0e901a735a68dd822608eec2f99b6c7b74 (diff)
downloadrails-0b92bb97c185f426585af770dcf43b67b0253f50.tar.gz
rails-0b92bb97c185f426585af770dcf43b67b0253f50.tar.bz2
rails-0b92bb97c185f426585af770dcf43b67b0253f50.zip
refactor some coupled rescue tests
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/test/controller/rescue_test.rb94
1 files changed, 78 insertions, 16 deletions
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index 741b01caa8..cc5a724081 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -400,22 +400,6 @@ class RescueControllerTest < ActionController::TestCase
assert_equal "RescueController::ResourceUnavailableToRescueAsString", @response.body
end
- def test_rescue_dispatcher_exceptions
- env = @request.env
- env["action_controller.rescue.request"] = @request
- env["action_controller.rescue.response"] = @response
-
- RescueController.call_with_exception(env, ActionController::RoutingError.new("Route not found"))
- assert_equal "no way", @response.body
- end
-
- def test_rescue_dispatcher_exceptions_without_request_set
- @request.env['REQUEST_URI'] = '/no_way'
- response = RescueController.call_with_exception(@request.env, ActionController::RoutingError.new("Route not found"))
- assert_kind_of ActionDispatch::Response, response
- assert_equal "no way", response.body
- end
-
protected
def with_all_requests_local(local = true)
old_local, ActionController::Base.consider_all_requests_local =
@@ -537,3 +521,81 @@ class ControllerInheritanceRescueControllerTest < ActionController::TestCase
assert_response :created
end
end
+
+class RescueTest < ActionController::IntegrationTest
+ class TestController < ActionController::Base
+ class RecordInvalid < StandardError
+ def message
+ 'invalid'
+ end
+ end
+ rescue_from RecordInvalid, :with => :show_errors
+
+ def foo
+ render :text => "foo"
+ end
+
+ def invalid
+ raise RecordInvalid
+ end
+
+ def b00m
+ raise 'b00m'
+ end
+
+ protected
+ def show_errors(exception)
+ render :text => exception.message
+ end
+ end
+
+ def setup
+ ActionController::Base.rescue_from ActionController::RoutingError do
+ render :text => 'no way'
+ end
+ end
+
+ def teardown
+ ActionController::Base.rescue_handlers.clear
+ end
+
+ test 'normal request' do
+ with_test_routing do
+ get '/foo'
+ assert_equal 'foo', response.body
+ end
+ end
+
+ test 'rescue exceptions inside controller' do
+ with_test_routing do
+ get '/invalid'
+ assert_equal 'invalid', response.body
+ end
+ end
+
+ test 'rescue routing exceptions' do
+ with_test_routing do
+ get '/no_way'
+ assert_equal 'no way', response.body
+ end
+ end
+
+ test 'unrescued exception' do
+ with_test_routing do
+ get '/b00m'
+ assert_match(/Action Controller: Exception caught/, response.body)
+ end
+ end
+
+ private
+ def with_test_routing
+ with_routing do |set|
+ set.draw do |map|
+ map.connect 'foo', :controller => "rescue_test/test", :action => 'foo'
+ map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid'
+ map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m'
+ end
+ yield
+ end
+ end
+end