1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #2497 from akaspick/url_for_fix

When calling url_for with a hash, additional (likely unwanted) values (such as :host) would be returned in the hash
This commit is contained in:
Santiago Pastorino 2011-08-11 15:55:14 -07:00
commit d1f1b04386
2 changed files with 13 additions and 1 deletions

View file

@ -140,7 +140,7 @@ module ActionDispatch
when String
options
when nil, Hash
_routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys)
_routes.url_for((options.dup || {}).reverse_merge!(url_options).symbolize_keys)
else
polymorphic_url(options)
end

View file

@ -851,6 +851,18 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
# tests the use of dup in url_for
def test_url_for_with_no_side_effects
# without dup, additional (and possibly unwanted) values will be present in the options (eg. :host)
original_options = {:controller => 'projects', :action => 'status'}
options = original_options.dup
url_for options
# verify that the options passed in have not changed from the original ones
assert_equal original_options, options
end
def test_projects_status
with_test_routes do
assert_equal '/projects/status', url_for(:controller => 'projects', :action => 'status', :only_path => true)