Permalink
Browse files

Make sure named routes are never generated relative to some containin…

…g module

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4442 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent e768dc6 commit 4e3543b46749a83e4ccf1e9346b4dfe6d1a03233 @jamis jamis committed Jun 6, 2006
Showing with 25 additions and 2 deletions.
  1. +2 −2 actionpack/lib/action_controller/routing.rb
  2. +23 −0 actionpack/test/controller/routing_test.rb
@@ -111,7 +111,7 @@ def write_generation
args = "options, hash, expire_on = {}"
# Nest the body inside of a def block, and then compile it.
- method_decl = "def generate_raw(#{args})\path = begin\n#{body}\nend\n[path, hash]\nend"
+ method_decl = "def generate_raw(#{args})\npath = begin\n#{body}\nend\n[path, hash]\nend"
# puts "\n======================"
# puts
# p self
@@ -971,7 +971,7 @@ def generate(options, recall = {}, method=:generate)
# current controller module, if any. In other words, if we're currently
# on admin/get, and the new controller is 'set', the new controller
# should really be admin/set.
- if expire_on[:controller] && options[:controller] && options[:controller][0] != ?/
+ if !named_route && expire_on[:controller] && options[:controller] && options[:controller][0] != ?/
old_parts = recall[:controller].split('/')
new_parts = options[:controller].split('/')
parts = old_parts[0..-(new_parts.length + 1)] + new_parts
@@ -1372,6 +1372,29 @@ def test_use_static_path_when_possible
{:controller => "welcome", :action => "get", :id => "7"})
assert_equal "/about", url
end
+
+ def test_generate_extras
+ set.draw { |map| map.connect ':controller/:action/:id' }
+
+ args = { :controller => "foo", :action => "bar", :id => "7", :x => "y" }
+ assert_equal "/foo/bar/7?x=y", set.generate(args)
+ assert_equal ["/foo/bar/7", [:x]], set.generate_extras(args)
+ assert_equal [:x], set.extra_keys(args)
+ end
+
+ def test_named_routes_are_never_relative_to_modules
+ set.draw do |map|
+ map.connect "/connection/manage/:action", :controller => 'connection/manage'
+ map.connect "/connection/connection", :controller => "connection/connection"
+ map.family_connection "/connection", :controller => "connection"
+ end
+
+ url = set.generate({:controller => "connection"}, {:controller => 'connection/manage'})
+ assert_equal "/connection/connection", url
+
+ url = set.generate({:use_route => :family_connection, :controller => "connection"}, {:controller => 'connection/manage'})
+ assert_equal "/connection", url
+ end
end
class RoutingTest < Test::Unit::TestCase

0 comments on commit 4e3543b

Please sign in to comment.