Permalink
Browse files

Fix missing formats in route-set URLs

Before this change, handle_positional_args would end up mutating @segment_keys
if inner_options included path components.  Subsequent calls would then
be missing the implicit path components.

eg:
user_path(1, :json)         # => "/users/1.json" (correct)
user_path(1, format: :json) # => "/users/1.json" (correct, but @segment_keys was mutated)
user_path(1, :json)         # => "/users/1" (oh no!)
  • Loading branch information...
jdelStrother committed Jun 22, 2017
1 parent 5de611a commit 2c0300389c3f6be00bf6c6b806332808a9400429
@@ -279,6 +279,8 @@ def handle_positional_args(controller_options, inner_options, args, result, path
if args.size < path_params_size
path_params -= controller_options.keys
path_params -= result.keys
else
path_params = path_params.dup
end
inner_options.each_key do |key|
path_params.delete(key)
@@ -138,6 +138,15 @@ def call(env)
assert_equal "/a/users/1", url_helpers.user_path(1, foo: "a")
end
test "implicit path components consistently return the same result" do
draw do
resources :users, to: SimpleApp.new("foo#index")
end
assert_equal "/users/1.json", url_helpers.user_path(1, :json)
assert_equal "/users/1.json", url_helpers.user_path(1, format: :json)
assert_equal "/users/1.json", url_helpers.user_path(1, :json)
end
private
def draw(&block)
@set.draw(&block)

0 comments on commit 2c03003

Please sign in to comment.