From 319ae4628f4e0058de3e40e4ca7791b17e45e70c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Jan 2009 18:54:01 -0600 Subject: Move HTTP libs and middleware into ActionDispatch component --- actionpack/test/controller/rescue_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/controller/rescue_test.rb') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 9f6b45f065..a2a2a3ee29 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -393,7 +393,7 @@ class RescueControllerTest < ActionController::TestCase 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 ActionController::Response, response + assert_kind_of ActionDispatch::Response, response assert_equal "no way", response.body end -- cgit v1.2.3 From 6c05b5e938ac48b69aec17c598fec447e38dde31 Mon Sep 17 00:00:00 2001 From: Yehuda Katz and Carl Lerche Date: Wed, 8 Apr 2009 17:33:06 -0700 Subject: Temporarily modifies setup to call super directly. This can support more T::U runners. --- actionpack/test/controller/rescue_test.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'actionpack/test/controller/rescue_test.rb') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index a2a2a3ee29..744ca9286c 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -143,8 +143,11 @@ end class RescueControllerTest < ActionController::TestCase FIXTURE_PUBLIC = "#{File.dirname(__FILE__)}/../fixtures".freeze - setup :set_all_requests_local - setup :populate_exception_object + def setup + super + set_all_requests_local + populate_exception_object + end def set_all_requests_local RescueController.consider_all_requests_local = true -- cgit v1.2.3 From 0b92bb97c185f426585af770dcf43b67b0253f50 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 21 Apr 2009 20:41:05 -0500 Subject: refactor some coupled rescue tests --- actionpack/test/controller/rescue_test.rb | 94 +++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 16 deletions(-) (limited to 'actionpack/test/controller/rescue_test.rb') 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 -- cgit v1.2.3 From 380431e4ed12d184c4e4891fbb74fdc38a51d2f2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 21 Apr 2009 21:11:23 -0500 Subject: Fix test_rescue_routing_exceptions when running with rake --- actionpack/test/controller/rescue_test.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'actionpack/test/controller/rescue_test.rb') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index cc5a724081..894420a910 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -522,6 +522,12 @@ class ControllerInheritanceRescueControllerTest < ActionController::TestCase end end +class ApplicationController < ActionController::Base + rescue_from ActionController::RoutingError do + render :text => 'no way' + end +end + class RescueTest < ActionController::IntegrationTest class TestController < ActionController::Base class RecordInvalid < StandardError @@ -549,16 +555,6 @@ class RescueTest < ActionController::IntegrationTest 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' @@ -574,9 +570,15 @@ class RescueTest < ActionController::IntegrationTest end test 'rescue routing exceptions' do - with_test_routing do - get '/no_way' - assert_equal 'no way', response.body + assert_equal 1, ApplicationController.rescue_handlers.length + + begin + with_test_routing do + get '/no_way' + assert_equal 'no way', response.body + end + ensure + ActionController::Base.rescue_handlers.clear end end -- cgit v1.2.3