From 24074796031d76d3ac2f5f0078d75699cce1bc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 21 Sep 2009 21:47:21 -0300 Subject: Fixes Sam Ruby tests suite. Signed-off-by: Yehuda Katz --- actionpack/test/controller/caching_test.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack/test/controller') 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 -- cgit v1.2.3 From 9f96708f53b4eee8830554dd8f0a482160ef4c73 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 24 Sep 2009 12:13:09 -0500 Subject: Resurrect AC::Benchmarking [#3140 state:resolved] --- actionpack/test/controller/logging_test.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'actionpack/test/controller') 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 -- cgit v1.2.3 From 088ce2904d63d15979de561b913e3e88e656f3fa Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 25 Sep 2009 11:10:39 -0500 Subject: Fix generic url rewriter in integration tests --- actionpack/test/controller/integration_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 9f56bbfd46..61668b72f1 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| @@ -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 -- cgit v1.2.3 From 1f7270057596592946a877cd029d95760ba3e5ee Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Sep 2009 13:41:32 -0500 Subject: Move default middleware stack into initializer --- actionpack/test/controller/dispatcher_test.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 150fc83cde..39e6f7d273 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -83,10 +83,6 @@ 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.call({'rack.input' => StringIO.new(''), 'action_dispatch.show_exceptions' => false}) -- cgit v1.2.3 From 198081a639deded3df8a1a526cee66e951fb51ec Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Sep 2009 19:57:36 -0500 Subject: Remove deprecated calls to Dispatcher.to_prepare --- actionpack/test/controller/dispatcher_test.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 39e6f7d273..8d974cb745 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -43,16 +43,11 @@ class DispatcherTest < Test::Unit::TestCase 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 +66,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 -- cgit v1.2.3 From acfeec515111d427b3a27aef3af034922e0d9248 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Sep 2009 20:51:05 -0500 Subject: Allow integration test rack app to be set with "@app" ivar instead of using open_session --- actionpack/test/controller/integration_test.rb | 2 +- actionpack/test/controller/rescue_test.rb | 7 ++----- actionpack/test/controller/webservice_test.rb | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 61668b72f1..0e4ca21143 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -394,7 +394,7 @@ class MetalIntegrationTest < ActionController::IntegrationTest end def setup - @integration_session = ActionController::Integration::Session.new(Poller) + @app = Poller end def test_successful_get 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 -- cgit v1.2.3 From 14866fa3d83676d340d94464f50e2e0ea989c3c1 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Sep 2009 21:38:48 -0500 Subject: Allow setting a default application for all integration tests --- actionpack/test/controller/dispatcher_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 8d974cb745..7ef2564e5a 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -22,7 +22,6 @@ class DispatcherTest < Test::Unit::TestCase def teardown Dispatcher.router = @old_router - @dispatcher = nil ENV.delete 'REQUEST_METHOD' end @@ -79,7 +78,7 @@ class DispatcherTest < Test::Unit::TestCase ActionController::Dispatcher.prepare_each_request = false Dispatcher.define_dispatcher_callbacks(cache_classes) - @dispatcher ||= Dispatcher.new + @dispatcher ||= ActionDispatch::Callbacks.new(Dispatcher.router) @dispatcher.call({'rack.input' => StringIO.new(''), 'action_dispatch.show_exceptions' => false}) end -- cgit v1.2.3 From a6757a02e12aa584bd74dbcde18a7886be8e9029 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Sep 2009 21:59:28 -0500 Subject: Move middleware and route configuration from AC::Dispatcher to Rails application object --- actionpack/test/controller/dispatcher_test.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 7ef2564e5a..622d67287d 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -14,14 +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 ENV.delete 'REQUEST_METHOD' end @@ -31,12 +29,12 @@ 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 @@ -78,7 +76,7 @@ class DispatcherTest < Test::Unit::TestCase ActionController::Dispatcher.prepare_each_request = false Dispatcher.define_dispatcher_callbacks(cache_classes) - @dispatcher ||= ActionDispatch::Callbacks.new(Dispatcher.router) + @dispatcher ||= ActionDispatch::Callbacks.new(ActionController::Routing::Routes) @dispatcher.call({'rack.input' => StringIO.new(''), 'action_dispatch.show_exceptions' => false}) end -- cgit v1.2.3