public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fixes optimised named routes generating question mark followed by nothing when 
provided an empty hash as the last argument.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#481 state:committed]
lukemelia (author)
Tue Jun 24 19:50:14 -0700 2008
NZKoz (committer)
Sun Aug 31 10:42:01 -0700 2008
commit  7ce03db77884e21256ba8f1615ad8dd841b76b86
tree    e6c957767638217305ac10a910074e57aab70571
parent  086c3520c47c6c001b3ddbba8881b4175c433ed1
...
103
104
105
106
 
 
107
108
 
109
110
111
...
103
104
105
 
106
107
108
 
109
110
111
112
0
@@ -103,9 +103,10 @@ module ActionController
0
         end
0
 
0
         # This case uses almost the same code as positional arguments,
0
-        # but add an args.last.to_query on the end
0
+        # but add a question mark and args.last.to_query on the end,
0
+        # unless the last arg is empty
0
         def generation_code
0
-          super.insert(-2, '?#{args.last.to_query}')
0
+          super.insert(-2, '#{\'?\' + args.last.to_query unless args.last.empty?}')
0
         end
0
 
0
         # To avoid generating "http://localhost/?host=foo.example.com" we
...
1694
1695
1696
 
 
 
 
 
 
1697
1698
1699
...
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
0
@@ -1694,6 +1694,12 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do
0
         controller.send(:multi_url, 7, "hello", 5, :baz => "bar")
0
     end
0
 
0
+    def test_named_route_url_method_with_ordered_parameters_and_empty_hash
0
+      controller = setup_named_route_test
0
+      assert_equal "http://named.route.test/people/go/7/hello/joe/5",
0
+        controller.send(:multi_url, 7, "hello", 5, {})
0
+    end
0
+
0
     def test_named_route_url_method_with_no_positional_arguments
0
       controller = setup_named_route_test
0
       assert_equal "http://named.route.test/people?baz=bar",

Comments