Skip to content
This repository
Browse code

Fix routes to generate proper URLs when given Fixnum defaults

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1768 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 4a3ec21b6261374ad58f3bc337fc8a547b6c490d 1 parent 05230c1
Nicholas Seckar authored July 08, 2005
2  actionpack/lib/action_controller/routing.rb
@@ -99,7 +99,7 @@ def initialize(key, options = {})
99 99
       def default_check(g)
100 100
         presence = "#{g.hash_value(key, !! default)}"
101 101
         if default
102  
-           "!(#{presence} && #{g.hash_value(key, false)} != #{default.inspect})"
  102
+           "!(#{presence} && #{g.hash_value(key, false)} != #{default.to_s.inspect})"
103 103
         else
104 104
           "! #{presence}"
105 105
         end
22  actionpack/test/controller/routing_test.rb
@@ -705,6 +705,10 @@ def test_paths_escaped
705 705
     results = rs.recognize_path %w(file hello+world how+are+you%3F)
706 706
     assert results, "Recognition should have succeeded"
707 707
     assert_equal ['hello world', 'how are you?'], results['path']
  708
+
  709
+    results = rs.recognize_path %w(file)
  710
+    assert results, "Recognition should have succeeded"
  711
+    assert_equal [], results['path']
708 712
   end
709 713
 
710 714
   def test_backwards
@@ -718,6 +722,24 @@ def test_backwards
718 722
     assert_equal ['/pages/boo', {}], rs.generate(:controller => 'pages', :action => 'boo')
719 723
   end
720 724
 
  725
+  def test_route_with_fixnum_default
  726
+    rs.draw do |map|
  727
+      rs.connect 'page/:id', :controller => 'content', :action => 'show_page', :id => 1
  728
+      rs.connect ':controller/:action/:id'
  729
+    end
  730
+
  731
+    assert_equal ['/page', {}], rs.generate(:controller => 'content', :action => 'show_page')
  732
+    assert_equal ['/page', {}], rs.generate(:controller => 'content', :action => 'show_page', :id => 1)
  733
+    assert_equal ['/page', {}], rs.generate(:controller => 'content', :action => 'show_page', :id => '1')
  734
+    assert_equal ['/page/10', {}], rs.generate(:controller => 'content', :action => 'show_page', :id => 10)
  735
+
  736
+    ctrl = ::Controllers::ContentController
  737
+
  738
+    assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => 1}, rs.recognize_path(%w(page)))
  739
+    assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => '1'}, rs.recognize_path(%w(page 1)))
  740
+    assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => '10'}, rs.recognize_path(%w(page 10)))
  741
+  end
  742
+
721 743
   def test_action_expiry
722 744
     assert_equal ['/content', {}], rs.generate({:controller => 'content'}, {:controller => 'content', :action => 'show'})
723 745
   end

0 notes on commit 4a3ec21

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