diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 47320883acfe0608885f974c4fe34563e85bb493..6bc4303be37f96e73f43a3892955cc22fa45cb71 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -203,7 +203,6 @@ def #{selector}(*args) url_for(options) end - protected :#{selector} END_EVAL helpers << selector end diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 88667d3570a3d5c855a7017d6aba2b9bb6b43738..0aff4250c1c7d6809a3b238dcc8f68f10ccf768d 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -162,12 +162,31 @@ def cookies # A running counter of the number of requests processed. attr_accessor :request_count + include ActionDispatch::Routing::UrlFor + # Create and initialize a new Session instance. def initialize(app) @app = app + + # If the app is a Rails app, make url_helpers available on the session + # This makes app.url_for and app.foo_path available in the console + if app.respond_to?(:routes) && app.routes.respond_to?(:url_helpers) + singleton_class.class_eval { include app.routes.url_helpers } + end + reset! end + def url_options + opts = super.reverse_merge( + :host => host, + :protocol => https? ? "https" : "http" + ) + + opts.merge!(:port => 443) if !opts.key?(:port) && https? + opts + end + # Resets the instance. This can be used to reset the state information # in an existing session instance, so it can be used from a clean-slate # condition. @@ -346,13 +365,8 @@ def copy_session_variables! #:nodoc: include ActionDispatch::Routing::UrlFor def url_options - opts = super.reverse_merge( - :host => host, - :protocol => https? ? "https" : "http" - ) - - opts.merge!(:port => 443) if !opts.key?(:port) && https? - opts + reset! unless @integration_session + @integration_session.url_options end # Delegate unhandled messages to the current session instance. diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index c95673d97e95b566cad0d0d070c6300815a835c2..c178dc481c342a7b40ddbc0e4acac52f6307f528 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -85,6 +85,7 @@ class TestCase class RoutedRackApp attr_reader :router + alias routes router def initialize(router, &blk) @router = router diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 67b6a1d85816523c542bc2962191f4d8f835d826..80c968cc0470ca45e32b384a83febfe84ac90f9c 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -511,7 +511,6 @@ def reset! @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @controller = ActionCachingTestController.new - # ROUTES TODO: It seems bad to explicitly remix in the class @controller.singleton_class.send(:include, @router.url_helpers) @request.host = 'hostname.com' end diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 5352243734a4e58fc39c186a0f997a229a247d49..c38348fa68a07b403ae105dcbc8f180ae62e0613 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -178,8 +178,8 @@ def test_opens_new_session session1 = @test.open_session { |sess| } session2 = @test.open_session # implicit session - assert_equal ::ActionController::Integration::Session, session1.class - assert_equal ::ActionController::Integration::Session, session2.class + assert_kind_of ::ActionController::Integration::Session, session1 + assert_kind_of ::ActionController::Integration::Session, session2 assert_not_equal session1, session2 end @@ -221,8 +221,6 @@ def test_integration_methods_called end class IntegrationProcessTest < ActionController::IntegrationTest - include SharedTestRoutes.url_helpers - class IntegrationController < ActionController::Base def get respond_to do |format| diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index cf0cab3690df44bc4ca6a7e1467d2ff6a506b309..f60045bba6086010393b0244694b008e147682e3 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1230,7 +1230,6 @@ def assert_restful_named_routes_for(controller_name, singular_name = nil, option end @controller = "#{options[:options][:controller].camelize}Controller".constantize.new - # ROUTES TODO: Figure out a way to not extend the routing helpers here @controller.singleton_class.send(:include, @router.url_helpers) @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new