aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-11-28 04:11:37 +0000
committerMichael Koziarski <michael@koziarski.com>2007-11-28 04:11:37 +0000
commit6a611e1e95ceec43473d2310678bfd6156899b7a (patch)
treeefc10f27d9154dec0a62218bdd0760aac1fa7a84 /actionpack
parent45d679bcb881adf8782230ff3b14ebc3a8d20e7b (diff)
downloadrails-6a611e1e95ceec43473d2310678bfd6156899b7a.tar.gz
rails-6a611e1e95ceec43473d2310678bfd6156899b7a.tar.bz2
rails-6a611e1e95ceec43473d2310678bfd6156899b7a.zip
Make sure the optimisation code for routes doesn't get used if :host, :anchor or :port are provided in the hash arguments. [pager, Koz] Closes #10292
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8227 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/routing_optimisation.rb2
-rw-r--r--actionpack/test/controller/routing_test.rb50
3 files changed, 48 insertions, 6 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index a42de8037e..141dcca5e6 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Make sure the optimisation code for routes doesn't get used if :host, :anchor or :port are provided in the hash arguments. [pager, Koz] #10292
+
* Added protection from trailing slashes on page caching #10229 [devrieda]
* Asset timestamps are appended, not prepended. Closes #10276 [mnaberez]
diff --git a/actionpack/lib/action_controller/routing_optimisation.rb b/actionpack/lib/action_controller/routing_optimisation.rb
index 9b109dce60..57c248a146 100644
--- a/actionpack/lib/action_controller/routing_optimisation.rb
+++ b/actionpack/lib/action_controller/routing_optimisation.rb
@@ -97,7 +97,7 @@ module ActionController
# argument
class PositionalArgumentsWithAdditionalParams < PositionalArguments
def guard_condition
- "defined?(request) && request && args.size == #{route.segment_keys.size + 1}"
+ "defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
end
# This case uses almost the Use the same code as positional arguments,
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 8be709a7f4..e784244c88 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -218,13 +218,12 @@ class LegacyRouteSetTests < Test::Unit::TestCase
x.send(:user_path, 3, :bar=>"foo")
end
- def test_optimized_named_route_with_host
+ def test_optimised_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
end
def setup_for_named_route
@@ -936,8 +935,16 @@ uses_mocha 'RouteTest' do
def url_for(options)
only_path = options.delete(:only_path)
+
+ port = options.delete(:port) || 80
+ port_string = port == 80 ? '' : ":#{port}"
+
+ host = options.delete(:host) || "named.route.test"
+ anchor = "##{options.delete(:anchor)}" if options.key?(:anchor)
+
path = routes.generate(options)
- only_path ? path : "http://named.route.test#{path}"
+
+ only_path ? "#{path}#{anchor}" : "http://#{host}#{port_string}#{path}#{anchor}"
end
def request
@@ -1553,7 +1560,40 @@ class RouteSetTest < Test::Unit::TestCase
assert_equal '/admin/users', set.generate(controller.send(:hash_for_users_url), {:controller => 'users', :action => 'index'})
end
- def test_namd_route_url_method_with_ordered_parameters
+ def test_named_route_url_method_with_anchor
+ controller = setup_named_route_test
+
+ assert_equal "http://named.route.test/people/5#location", controller.send(:show_url, :id => 5, :anchor => 'location')
+ assert_equal "/people/5#location", controller.send(:show_path, :id => 5, :anchor => 'location')
+
+ assert_equal "http://named.route.test/people#location", controller.send(:index_url, :anchor => 'location')
+ assert_equal "/people#location", controller.send(:index_path, :anchor => 'location')
+
+ assert_equal "http://named.route.test/admin/users#location", controller.send(:users_url, :anchor => 'location')
+ assert_equal '/admin/users#location', controller.send(:users_path, :anchor => 'location')
+
+ assert_equal "http://named.route.test/people/go/7/hello/joe/5#location",
+ controller.send(:multi_url, 7, "hello", 5, :anchor => 'location')
+
+ assert_equal "http://named.route.test/people/go/7/hello/joe/5?baz=bar#location",
+ controller.send(:multi_url, 7, "hello", 5, :baz => "bar", :anchor => 'location')
+
+ assert_equal "http://named.route.test/people?baz=bar#location",
+ controller.send(:index_url, :baz => "bar", :anchor => 'location')
+ end
+
+ def test_named_route_url_method_with_port
+ controller = setup_named_route_test
+ assert_equal "http://named.route.test:8080/people/5", controller.send(:show_url, 5, :port=>8080)
+ end
+
+ def test_named_route_url_method_with_host
+ controller = setup_named_route_test
+ assert_equal "http://some.example.com/people/5", controller.send(:show_url, 5, :host=>"some.example.com")
+ end
+
+
+ def test_named_route_url_method_with_ordered_parameters
controller = setup_named_route_test
assert_equal "http://named.route.test/people/go/7/hello/joe/5",
controller.send(:multi_url, 7, "hello", 5)