diff options
Diffstat (limited to 'actionpack/test/controller/dispatcher_test.rb')
-rw-r--r-- | actionpack/test/controller/dispatcher_test.rb | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 61bfb2b6e9..30dda87bb4 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -6,7 +6,6 @@ class DispatcherTest < Test::Unit::TestCase Dispatcher = ActionController::Dispatcher def setup - @output = StringIO.new ENV['REQUEST_METHOD'] = 'GET' # Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks @@ -16,7 +15,7 @@ class DispatcherTest < Test::Unit::TestCase Dispatcher.stubs(:require_dependency) - @dispatcher = Dispatcher.new(@output) + @dispatcher = Dispatcher.new end def teardown @@ -25,17 +24,17 @@ class DispatcherTest < Test::Unit::TestCase def test_clears_dependencies_after_dispatch_if_in_loading_mode ActiveSupport::Dependencies.expects(:clear).once - dispatch(@output, false) + dispatch(false) end def test_reloads_routes_before_dispatch_if_in_loading_mode ActionController::Routing::Routes.expects(:reload).once - dispatch(@output, false) + dispatch(false) end def test_clears_asset_tag_cache_before_dispatch_if_in_loading_mode ActionView::Helpers::AssetTagHelper::AssetTag::Cache.expects(:clear).once - dispatch(@output, false) + dispatch(false) end def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode @@ -51,12 +50,16 @@ class DispatcherTest < Test::Unit::TestCase end def test_failsafe_response - CGI.expects(:new).raises('some multipart parsing failure') - Dispatcher.expects(:log_failsafe_exception) - - assert_nothing_raised { dispatch } - - assert_equal "Status: 400 Bad Request\r\nContent-Type: text/html\r\n\r\n<html><body><h1>400 Bad Request</h1></body></html>", @output.string + Dispatcher.any_instance.expects(:dispatch_unlocked).raises('b00m') + ActionController::Failsafe.any_instance.expects(:log_failsafe_exception) + + assert_nothing_raised do + assert_equal [ + 500, + {"Content-Type" => "text/html"}, + "<html><body><h1>500 Internal Server Error</h1></body></html>" + ], dispatch + end end def test_prepare_callbacks @@ -77,7 +80,7 @@ class DispatcherTest < Test::Unit::TestCase # Make sure they are only run once a = b = c = nil - @dispatcher.send :dispatch + dispatch assert_nil a || b || c end @@ -92,15 +95,10 @@ class DispatcherTest < Test::Unit::TestCase end private - def dispatch(output = @output, cache_classes = true) - controller = mock - controller.stubs(:process).returns(controller) - controller.stubs(:out).with(output).returns('response') - - ActionController::Routing::Routes.stubs(:recognize).returns(controller) - + def dispatch(cache_classes = true) + Dispatcher.any_instance.stubs(:handle_request).returns([200, {}, 'response']) Dispatcher.define_dispatcher_callbacks(cache_classes) - Dispatcher.dispatch(nil, {}, output) + @dispatcher.call({}) end def assert_subclasses(howmany, klass, message = klass.subclasses.inspect) |