From 275e839b8dfa3cf2bdedf1b31302dec20ac96a46 Mon Sep 17 00:00:00 2001 From: J Smith Date: Wed, 21 Apr 2010 21:37:51 -0400 Subject: Ensure that url_for uses symbolized keys in the controller. [#4391] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_dispatch/routing/url_for.rb | 2 +- actionpack/test/controller/url_for_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index fb236dce53..394d5a6248 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -128,7 +128,7 @@ module ActionDispatch when String options when nil, Hash - _router.url_for(url_options.merge(options || {})) + _router.url_for(url_options.merge(options || {}).symbolize_keys) else polymorphic_url(options) end diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index fc7773dffe..501f928e05 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -257,6 +257,16 @@ module AbstractController assert_equal second_class.default_url_options[:host], second_host end + def test_with_stringified_keys + assert_equal("/c/a", W.new.url_for('controller' => 'c', 'action' => 'a', 'only_path' => true)) + assert_equal("/c", W.new.url_for('controller' => 'c', 'only_path' => true)) + end + + def test_with_hash_with_indifferent_access + assert_equal("/c/a", W.new.url_for(HashWithIndifferentAccess.new('controller' => 'c', 'action' => 'a', 'only_path' => true))) + assert_equal("/c", W.new.url_for(HashWithIndifferentAccess.new('controller' => 'c', 'only_path' => true))) + end + private def extract_params(url) url.split('?', 2).last.split('&').sort -- cgit v1.2.3