Skip to content

Commit

Permalink
Merge pull request #3099 from wrozka/master
Browse files Browse the repository at this point in the history
Named routes are modifying passed options
  • Loading branch information
josevalim committed Sep 22, 2011
2 parents 2bf33bd + 019eea4 commit 8de0bbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Expand Up @@ -165,13 +165,14 @@ def define_hash_access(route, name, kind, options)
remove_possible_method :#{selector}
def #{selector}(*args)
options = args.extract_options!
result = #{options.inspect}
if args.any?
options[:_positional_args] = args
options[:_positional_keys] = #{route.segment_keys.inspect}
result[:_positional_args] = args
result[:_positional_keys] = #{route.segment_keys.inspect}
end
options ? #{options.inspect}.merge(options) : #{options.inspect}
result.merge(options)
end
protected :#{selector}
END_EVAL
Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Expand Up @@ -863,6 +863,17 @@ def test_url_for_with_no_side_effects
assert_equal original_options, options
end

# tests the arguments modification free version of define_hash_access
def test_named_route_with_no_side_effects
original_options = { :host => 'test.host' }
options = original_options.dup

profile_customer_url("customer_model", 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)
Expand Down

0 comments on commit 8de0bbe

Please sign in to comment.