Skip to content
This repository
Browse code

Fix routing to correctly determine when generation fails. Closes #6300.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5314 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 03b383853d3e1de85cf1b345e2b0dd5cb1f42479 1 parent d1ae92e
Nicholas Seckar authored October 16, 2006
2  actionpack/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Fix routing to correctly determine when generation fails. Closes #6300. [psross].
  4
+
3 5
 * Fix broken assert_generates when extra keys are being checked. [Jamis Buck]
4 6
 
5 7
 * Replace KCODE checks with String#chars for truncate.  Closes #6385 [Manfred Stienstra]
2  actionpack/lib/action_controller/routing.rb
@@ -1229,7 +1229,7 @@ def generate(options, recall = {}, method=:generate)
1229 1229
 
1230 1230
           routes.each do |route|
1231 1231
             results = route.send(method, options, merged, expire_on)
1232  
-            return results if results
  1232
+            return results if results && (!results.is_a?(Array) || results.first)
1233 1233
           end
1234 1234
         end
1235 1235
     
27  actionpack/test/controller/routing_test.rb
@@ -1253,6 +1253,33 @@ def test_extra_keys
1253 1253
     extras = set.extra_keys(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
1254 1254
     assert_equal %w(that this), extras.map(&:to_s).sort
1255 1255
   end
  1256
+  
  1257
+  def test_generate_extras_not_first
  1258
+    set.draw do |map| 
  1259
+      map.connect ':controller/:action/:id.:format'
  1260
+      map.connect ':controller/:action/:id'
  1261
+    end    
  1262
+    path, extras = set.generate_extras(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
  1263
+    assert_equal "/foo/bar/15", path
  1264
+    assert_equal %w(that this), extras.map(&:to_s).sort
  1265
+  end
  1266
+  
  1267
+  def test_generate_not_first
  1268
+    set.draw do |map| 
  1269
+      map.connect ':controller/:action/:id.:format'
  1270
+      map.connect ':controller/:action/:id'
  1271
+    end    
  1272
+    assert_equal "/foo/bar/15?this=hello", set.generate(:controller => "foo", :action => "bar", :id => 15, :this => "hello")
  1273
+  end
  1274
+  
  1275
+  def test_extra_keys_not_first
  1276
+    set.draw do |map| 
  1277
+      map.connect ':controller/:action/:id.:format'
  1278
+      map.connect ':controller/:action/:id'
  1279
+    end
  1280
+    extras = set.extra_keys(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
  1281
+    assert_equal %w(that this), extras.map(&:to_s).sort
  1282
+  end   
1256 1283
 
1257 1284
   def test_draw
1258 1285
     assert_equal 0, set.routes.size

0 notes on commit 03b3838

Please sign in to comment.
Something went wrong with that request. Please try again.