Skip to content

Commit

Permalink
Fixes optimised named routes generating question mark followed by not…
Browse files Browse the repository at this point in the history
…hing when provided an empty hash as the last argument.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#481 state:committed]
  • Loading branch information
lukemelia authored and NZKoz committed Aug 31, 2008
1 parent 086c352 commit 7ce03db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions actionpack/lib/action_controller/routing/optimisations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ def guard_condition
end

# This case uses almost the same code as positional arguments,
# but add an args.last.to_query on the end
# but add a question mark and args.last.to_query on the end,
# unless the last arg is empty
def generation_code
super.insert(-2, '?#{args.last.to_query}')
super.insert(-2, '#{\'?\' + args.last.to_query unless args.last.empty?}')
end

# To avoid generating "http://localhost/?host=foo.example.com" we
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/controller/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,12 @@ def test_named_route_url_method_with_ordered_parameters_and_hash
controller.send(:multi_url, 7, "hello", 5, :baz => "bar")
end

def test_named_route_url_method_with_ordered_parameters_and_empty_hash
controller = setup_named_route_test
assert_equal "http://named.route.test/people/go/7/hello/joe/5",
controller.send(:multi_url, 7, "hello", 5, {})
end

def test_named_route_url_method_with_no_positional_arguments
controller = setup_named_route_test
assert_equal "http://named.route.test/people?baz=bar",
Expand Down

0 comments on commit 7ce03db

Please sign in to comment.