Unique the segment keys array for non-optimized url helpers

In Rails 3.2 you only needed pass an argument for dynamic segment once so
unique the segment keys array to match the number of args. Since the number
of args is less than required parts the non-optimized code path is selected.
This means to benefit from optimized url generation the arg needs to be
specified as many times as it appears in the path.

Fixes #12808
This commit is contained in:
Andrew White 2014-01-05 11:57:50 +00:00
parent 892c539591
commit 6b54883082
3 changed files with 31 additions and 1 deletions

@ -1,3 +1,15 @@
* Unique the segment keys array for non-optimized url helpers
In Rails 3.2 you only needed pass an argument for dynamic segment once so
unique the segment keys array to match the number of args. Since the number
of args is less than required parts the non-optimized code path is selected.
This means to benefit from optimized url generation the arg needs to be
specified as many times as it appears in the path.
Fixes #12808
*Andrew White*
* Show full route constraints in error message
When an optimized helper fails to generate, show the full route constraints

@ -220,7 +220,7 @@ def raise_generation_error(args, missing_keys)
def initialize(route, options)
@options = options
@segment_keys = route.segment_keys
@segment_keys = route.segment_keys.uniq
@route = route
end

@ -2864,6 +2864,24 @@ def test_action_from_path_is_not_frozen
assert !@request.params[:action].frozen?
end
def test_multiple_positional_args_with_the_same_name
draw do
get '/downloads/:id/:id.tar' => 'downloads#show', as: :download, format: false
end
expected_params = {
controller: 'downloads',
action: 'show',
id: '1'
}
get '/downloads/1/1.tar'
assert_equal 'downloads#show', @response.body
assert_equal expected_params, @request.symbolized_path_parameters
assert_equal '/downloads/1/1.tar', download_path('1')
assert_equal '/downloads/1/1.tar', download_path('1', '1')
end
private
def draw(&block)