Skip to content
Browse files

Merge pull request #5750 from ahoward/master

mo fasta and mo betta the url_for
  • Loading branch information...
2 parents 7ecd6a7 + 99c08c7 commit 174cf8b22064c3999dfa685014d5b31ac993bb54 @tenderlove tenderlove committed Apr 5, 2012
Showing with 22 additions and 2 deletions.
  1. +13 −2 actionpack/lib/action_dispatch/routing/url_for.rb
  2. +9 −0 actionpack/test/controller/url_for_test.rb
View
15 actionpack/lib/action_dispatch/routing/url_for.rb
@@ -144,10 +144,21 @@ def url_options
# # => 'http://somehost.org/tasks/testing?number=33'
def url_for(options = nil)
case options
+ when nil
+ _routes.url_for(url_options)
+ when Hash
+ symbolized = {}
+ options.keys.each do |k|
+ sym = k.to_sym
+ symbolized[sym] = options[k] unless symbolized.has_key?(sym)
+ end
+ url_options.keys.each do |k|
+ sym = k.to_sym
+ symbolized[sym] = url_options[k] unless symbolized.has_key?(sym)
+ end
+ _routes.url_for(symbolized)
when String
options
- when nil, Hash
- _routes.url_for((options || {}).symbolize_keys.reverse_merge!(url_options))
else
polymorphic_url(options)
end
View
9 actionpack/test/controller/url_for_test.rb
@@ -356,6 +356,15 @@ def test_with_hash_with_indifferent_access
assert_equal("/c/a", W.new.url_for(HashWithIndifferentAccess.new('controller' => 'c', 'action' => 'a', 'only_path' => true)))
end
+ def test_with_stringified_default_url_options
+ W.default_url_options['controller'] = 'd'
+ W.default_url_options['only_path'] = false
+ assert_equal("/c", W.new.url_for(:controller => 'c', :only_path => true))
+
+ W.default_url_options['action'] = 'b'
+ assert_equal("/c/a", W.new.url_for(:controller => 'c', :action => 'a', :only_path => true))
+ end
+
def test_url_params_with_nil_to_param_are_not_in_url
assert_equal("/c/a", W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :id => Struct.new(:to_param).new(nil)))
end

0 comments on commit 174cf8b

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