diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-09-30 22:27:02 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-09-30 22:27:02 +0100 |
commit | dd2779e1b83b4d867d47dd286ec0c919f5df12a9 (patch) | |
tree | 6e52ea0a329c24429f4d1d41b065e082f0ed6baa /actionpack/test/controller | |
parent | 329b14aa8fdd291a00d17ba12c2e0ab4c3a157cc (diff) | |
parent | 420004e030e96f2ace6e27fd622c90ee9e986677 (diff) | |
download | rails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.tar.gz rails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.tar.bz2 rails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/caching_test.rb | 5 | ||||
-rw-r--r-- | actionpack/test/controller/dispatcher_test.rb | 32 | ||||
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 11 | ||||
-rw-r--r-- | actionpack/test/controller/logging_test.rb | 23 | ||||
-rw-r--r-- | actionpack/test/controller/rescue_test.rb | 7 | ||||
-rw-r--r-- | actionpack/test/controller/webservice_test.rb | 4 |
6 files changed, 37 insertions, 45 deletions
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index bd17df73c7..1a9f95e5e9 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -631,9 +631,8 @@ class FragmentCachingTest < ActionController::TestCase buffer = 'generated till now -> ' @controller.fragment_for(buffer, 'expensive') { fragment_computed = true } - assert_equal 2, listener.size - assert_equal :fragment_exist?, listener[0].name - assert_equal :write_fragment, listener[1].name + assert_equal 1, listener.count { |e| e.name == :fragment_exist? } + assert_equal 1, listener.count { |e| e.name == :write_fragment } assert fragment_computed assert_equal 'generated till now -> ', buffer diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 150fc83cde..622d67287d 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -14,15 +14,12 @@ class DispatcherTest < Test::Unit::TestCase ActionDispatch::Callbacks.reset_callbacks(:prepare) ActionDispatch::Callbacks.reset_callbacks(:call) - @old_router, Dispatcher.router = Dispatcher.router, mock() - Dispatcher.router.stubs(:call).returns([200, {}, 'response']) - Dispatcher.router.stubs(:reload) + ActionController::Routing::Routes.stubs(:call).returns([200, {}, 'response']) + ActionController::Routing::Routes.stubs(:reload) Dispatcher.stubs(:require_dependency) end def teardown - Dispatcher.router = @old_router - @dispatcher = nil ENV.delete 'REQUEST_METHOD' end @@ -32,27 +29,22 @@ class DispatcherTest < Test::Unit::TestCase end def test_reloads_routes_before_dispatch_if_in_loading_mode - Dispatcher.router.expects(:reload).once + ActionController::Routing::Routes.expects(:reload).once dispatch(false) end def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode - Dispatcher.router.expects(:reload).never + ActionController::Routing::Routes.expects(:reload).never ActiveSupport::Dependencies.expects(:clear).never dispatch end - # Stub out dispatch error logger - class << Dispatcher - def log_failsafe_exception(status, exception); end - end - def test_prepare_callbacks a = b = c = nil - Dispatcher.to_prepare { |*args| a = b = c = 1 } - Dispatcher.to_prepare { |*args| b = c = 2 } - Dispatcher.to_prepare { |*args| c = 3 } + ActionDispatch::Callbacks.to_prepare { |*args| a = b = c = 1 } + ActionDispatch::Callbacks.to_prepare { |*args| b = c = 2 } + ActionDispatch::Callbacks.to_prepare { |*args| c = 3 } # Ensure to_prepare callbacks are not run when defined assert_nil a || b || c @@ -71,8 +63,8 @@ class DispatcherTest < Test::Unit::TestCase end def test_to_prepare_with_identifier_replaces - Dispatcher.to_prepare(:unique_id) { |*args| Foo.a, Foo.b = 1, 1 } - Dispatcher.to_prepare(:unique_id) { |*args| Foo.a = 2 } + ActionDispatch::Callbacks.to_prepare(:unique_id) { |*args| Foo.a, Foo.b = 1, 1 } + ActionDispatch::Callbacks.to_prepare(:unique_id) { |*args| Foo.a = 2 } dispatch assert_equal 2, Foo.a @@ -83,12 +75,8 @@ class DispatcherTest < Test::Unit::TestCase def dispatch(cache_classes = true) ActionController::Dispatcher.prepare_each_request = false Dispatcher.define_dispatcher_callbacks(cache_classes) - Dispatcher.middleware = ActionDispatch::MiddlewareStack.new do |middleware| - middlewares = File.expand_path(File.join(File.dirname(__FILE__), "../../lib/action_controller/dispatch/middlewares.rb")) - middleware.instance_eval(File.read(middlewares)) - end - @dispatcher ||= Dispatcher.new + @dispatcher ||= ActionDispatch::Callbacks.new(ActionController::Routing::Routes) @dispatcher.call({'rack.input' => StringIO.new(''), 'action_dispatch.show_exceptions' => false}) end diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 9f56bbfd46..0e4ca21143 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'controller/fake_controllers' require 'action_controller/vendor/html-scanner' class SessionTest < Test::Unit::TestCase @@ -363,6 +364,10 @@ class IntegrationProcessTest < ActionController::IntegrationTest end end + def test_generate_url_with_controller + assert_equal 'http://www.example.com/foo', url_for(:controller => "foo") + end + private def with_test_route_set with_routing do |set| @@ -389,7 +394,7 @@ class MetalIntegrationTest < ActionController::IntegrationTest end def setup - @integration_session = ActionController::Integration::Session.new(Poller) + @app = Poller end def test_successful_get @@ -406,4 +411,8 @@ class MetalIntegrationTest < ActionController::IntegrationTest assert_response :not_found assert_equal '', response.body end + + def test_generate_url_without_controller + assert_equal 'http://www.example.com/foo', url_for(:controller => "foo") + end end diff --git a/actionpack/test/controller/logging_test.rb b/actionpack/test/controller/logging_test.rb index 98ffbc3813..2b5e8d8bde 100644 --- a/actionpack/test/controller/logging_test.rb +++ b/actionpack/test/controller/logging_test.rb @@ -12,11 +12,11 @@ class LoggingTest < ActionController::TestCase class MockLogger attr_reader :logged attr_accessor :level - + def initialize @level = Logger::DEBUG end - + def method_missing(method, *args, &blk) @logged ||= [] @logged << args.first @@ -31,25 +31,24 @@ class LoggingTest < ActionController::TestCase def test_logging_without_parameters get :show - assert_equal 2, logs.size + assert_equal 3, logs.size assert_nil logs.detect {|l| l =~ /Parameters/ } end def test_logging_with_parameters get :show, :id => '10' - assert_equal 3, logs.size + assert_equal 4, logs.size params = logs.detect {|l| l =~ /Parameters/ } assert_equal 'Parameters: {"id"=>"10"}', params end - + private + def set_logger + @controller.logger = MockLogger.new + end - def set_logger - @controller.logger = MockLogger.new - end - - def logs - @logs ||= @controller.logger.logged.compact.map {|l| l.to_s.strip} - end + def logs + @logs ||= @controller.logger.logged.compact.map {|l| l.to_s.strip} + end end diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 09eddfe4a7..6ad708bba1 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -326,19 +326,16 @@ class RescueTest < ActionController::IntegrationTest end test 'rescue routing exceptions' do - app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) do + @app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) do rescue_from ActionController::RoutingError, lambda { |env| [200, {"Content-Type" => "text/html"}, "Gotcha!"] } end - @integration_session = open_session(app) get '/b00m' assert_equal "Gotcha!", response.body end test 'unrescued exception' do - app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) - @integration_session = open_session(app) - + @app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) assert_raise(ActionController::RoutingError) { get '/b00m' } end diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index 916124e221..c04d20fbad 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -245,8 +245,8 @@ class WebServiceTest < ActionController::IntegrationTest private def with_params_parsers(parsers = {}) old_session = @integration_session - app = ActionDispatch::ParamsParser.new(ActionController::Routing::Routes, parsers) - @integration_session = open_session(app) + @app = ActionDispatch::ParamsParser.new(ActionController::Routing::Routes, parsers) + reset! yield ensure @integration_session = old_session |