Skip to content
Browse files

Get URL helpers working again in integration tests.

  • Loading branch information...
1 parent fc4582f commit 8760add31a0415b4635059cf7fadabc26946c0c2 Carlhuda committed Feb 25, 2010
View
2 actionpack/lib/action_controller/railtie.rb
@@ -32,6 +32,8 @@ class Railtie < Rails::Railtie
initializer "action_controller.url_helpers" do |app|
ActionController::Base.extend ::ActionController::Railtie::UrlHelpers.with(app.routes)
+ ActionController::Routing::Routes = app.routes
+ ::SharedTestRoutes = app.routes
end
end
end
View
48 actionpack/lib/action_dispatch/testing/integration.rb
@@ -219,17 +219,17 @@ def host!(name)
@host = name
end
- # Returns the URL for the given options, according to the rules specified
- # in the application's routes.
- def url_for(options)
- # ROUTES TODO: @app.router is not guaranteed to exist, so a generic Rack
- # application will not work here. This means that a generic Rack application
- # integration test cannot call url_for, since the application will not have
- # #router on it.
- controller ?
- controller.url_for(options) :
- generic_url_rewriter.rewrite(SharedTestRoutes, options)
- end
+ # # Returns the URL for the given options, according to the rules specified
+ # # in the application's routes.
+ # def url_for(options)
+ # # ROUTES TODO: @app.router is not guaranteed to exist, so a generic Rack
+ # # application will not work here. This means that a generic Rack application
+ # # integration test cannot call url_for, since the application will not have
+ # # #router on it.
+ # controller ?
+ # controller.url_for(options) :
+ # generic_url_rewriter.rewrite(SharedTestRoutes, options)
+ # end
private
@@ -283,19 +283,6 @@ def process(method, path, parameters = nil, rack_environment = nil)
return response.status
end
-
- # Get a temporary URL writer object
- def generic_url_rewriter
- env = {
- 'REQUEST_METHOD' => "GET",
- 'QUERY_STRING' => "",
- "REQUEST_URI" => "/",
- "HTTP_HOST" => host,
- "SERVER_PORT" => https? ? "443" : "80",
- "HTTPS" => https? ? "on" : "off"
- }
- ActionController::UrlRewriter.new(ActionDispatch::Request.new(env), {})
- end
end
module Runner
@@ -367,6 +354,19 @@ def copy_session_variables! #:nodoc:
end
end
+ extend ActiveSupport::Concern
+ include ActionDispatch::Routing::UrlFor
+
+ def merge_options(options)
+ opts = super.reverse_merge(
+ :host => host,
+ :protocol => https? ? "https" : "http"
+ )
+
+ opts.merge!(:port => 443) if !opts.key?(:port) && https?
+ opts
+ end
+
# Delegate unhandled messages to the current session instance.
def method_missing(sym, *args, &block)
reset! unless @integration_session
View
24 actionpack/test/controller/integration_test.rb
@@ -75,23 +75,6 @@ def test_delete_via_redirect
@session.delete_via_redirect(path, args, headers)
end
- def test_url_for_with_controller
- options = {:action => 'show'}
- mock_controller = mock()
- mock_controller.expects(:url_for).with(options).returns('/show')
- @session.stubs(:controller).returns(mock_controller)
- assert_equal '/show', @session.url_for(options)
- end
-
- def test_url_for_without_controller
- options = {:action => 'show'}
- mock_rewriter = mock()
- mock_rewriter.expects(:rewrite).with(SharedTestRoutes, options).returns('/show')
- @session.stubs(:generic_url_rewriter).returns(mock_rewriter)
- @session.stubs(:controller).returns(nil)
- assert_equal '/show', @session.url_for(options)
- end
-
def test_get
path = "/index"; params = "blah"; headers = {:location => 'blah'}
@session.expects(:process).with(:get,path,params,headers)
@@ -238,6 +221,8 @@ def test_integration_methods_called
end
class IntegrationProcessTest < ActionController::IntegrationTest
+ include SharedTestRoutes.named_url_helpers
+
class IntegrationController < ActionController::Base
def get
respond_to do |format|
@@ -410,12 +395,17 @@ def with_test_route_set
match ':action', :to => controller
get 'get/:action', :to => controller
end
+
+ self.metaclass.send(:include, set.named_url_helpers)
+
yield
end
end
end
class MetalIntegrationTest < ActionController::IntegrationTest
+ include SharedTestRoutes.named_url_helpers
+
class Poller
def self.call(env)
if env["PATH_INFO"] =~ /^\/success/
View
4 railties/lib/rails/test_help.rb
@@ -30,6 +30,10 @@ class ActionController::TestCase
end
end
+class ActionDispatch::IntegrationTest
+ include Rails.application.routes.named_url_helpers
+end
+
begin
require_library_or_gem 'ruby-debug'
Debugger.start

0 comments on commit 8760add

Please sign in to comment.
Something went wrong with that request. Please try again.