Ensure that the routing optimisation code isn't used when additional arguments are passed to the named route. Closes #10209 [bscofield, Koz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8169 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
e1a2f3c898
commit
0c12d6c6dc
|
@ -273,6 +273,8 @@ module ActionController
|
|||
|
||||
HTTP_METHODS = [:get, :head, :post, :put, :delete]
|
||||
|
||||
ALLOWED_REQUIREMENTS_FOR_OPTIMISATION = [:controller, :action].to_set
|
||||
|
||||
# The root paths which may contain controller files
|
||||
mattr_accessor :controller_paths
|
||||
self.controller_paths = []
|
||||
|
@ -353,6 +355,7 @@ module ActionController
|
|||
@segments = []
|
||||
@requirements = {}
|
||||
@conditions = {}
|
||||
@optimise = true
|
||||
end
|
||||
|
||||
# Indicates whether the routes should be optimised with the string interpolation
|
||||
|
@ -1021,15 +1024,18 @@ module ActionController
|
|||
route.requirements = requirements
|
||||
route.conditions = conditions
|
||||
|
||||
# Routes cannot use the current string interpolation method
|
||||
# if there are user-supplied :requirements as the interpolation
|
||||
# code won't raise RoutingErrors when generating
|
||||
route.optimise = !options.key?(:requirements)
|
||||
if !route.significant_keys.include?(:action) && !route.requirements[:action]
|
||||
route.requirements[:action] = "index"
|
||||
route.significant_keys << :action
|
||||
end
|
||||
|
||||
# Routes cannot use the current string interpolation method
|
||||
# if there are user-supplied :requirements as the interpolation
|
||||
# code won't raise RoutingErrors when generating
|
||||
if options.key?(:requirements) || route.requirements.keys.to_set != Routing::ALLOWED_REQUIREMENTS_FOR_OPTIMISATION
|
||||
route.optimise = false
|
||||
end
|
||||
|
||||
if !route.significant_keys.include?(:controller)
|
||||
raise ArgumentError, "Illegal route: the :controller must be specified!"
|
||||
end
|
||||
|
|
|
@ -212,11 +212,19 @@ class LegacyRouteSetTests < Test::Unit::TestCase
|
|||
rs.add_named_route :user, 'admin/user/:id', :controller=>'/admin/user', :action=>'show'
|
||||
x = setup_for_named_route
|
||||
x.expects(:url_for).never
|
||||
# x.send(:users_url)
|
||||
x.send(:users_url)
|
||||
x.send(:users_path)
|
||||
# x.send(:user_url, 2, :foo=>"bar")
|
||||
x.send(:user_url, 2, :foo=>"bar")
|
||||
x.send(:user_path, 3, :bar=>"foo")
|
||||
end
|
||||
|
||||
def test_optimized_named_route_with_host
|
||||
rs.add_named_route :pages, 'pages', :controller => 'content', :action => 'show_page', :host => 'foo.com'
|
||||
x = setup_for_named_route
|
||||
x.expects(:url_for).with(:host => 'foo.com', :only_path => false, :controller => 'content', :action => 'show_page', :use_route => :pages).once
|
||||
x.send(:pages_url)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def setup_for_named_route
|
||||
|
|
Loading…
Reference in New Issue