diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2005-07-08 08:45:51 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2005-07-08 08:45:51 +0000 |
commit | 4a3ec21b6261374ad58f3bc337fc8a547b6c490d (patch) | |
tree | 7d2e2e9ba318161b5debe75400ee8e5e861b942e /actionpack | |
parent | 05230c13f664b6423bbd000814170172511e48be (diff) | |
download | rails-4a3ec21b6261374ad58f3bc337fc8a547b6c490d.tar.gz rails-4a3ec21b6261374ad58f3bc337fc8a547b6c490d.tar.bz2 rails-4a3ec21b6261374ad58f3bc337fc8a547b6c490d.zip |
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
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/routing.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 41f61bdb0d..32ce0db3aa 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -99,7 +99,7 @@ module ActionController def default_check(g) presence = "#{g.hash_value(key, !! default)}" if default - "!(#{presence} && #{g.hash_value(key, false)} != #{default.inspect})" + "!(#{presence} && #{g.hash_value(key, false)} != #{default.to_s.inspect})" else "! #{presence}" end diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 93d16c6f65..c68b1f70d3 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -705,6 +705,10 @@ class RouteSetTests < Test::Unit::TestCase results = rs.recognize_path %w(file hello+world how+are+you%3F) assert results, "Recognition should have succeeded" assert_equal ['hello world', 'how are you?'], results['path'] + + results = rs.recognize_path %w(file) + assert results, "Recognition should have succeeded" + assert_equal [], results['path'] end def test_backwards @@ -718,6 +722,24 @@ class RouteSetTests < Test::Unit::TestCase assert_equal ['/pages/boo', {}], rs.generate(:controller => 'pages', :action => 'boo') end + def test_route_with_fixnum_default + rs.draw do |map| + rs.connect 'page/:id', :controller => 'content', :action => 'show_page', :id => 1 + rs.connect ':controller/:action/:id' + end + + assert_equal ['/page', {}], rs.generate(:controller => 'content', :action => 'show_page') + assert_equal ['/page', {}], rs.generate(:controller => 'content', :action => 'show_page', :id => 1) + assert_equal ['/page', {}], rs.generate(:controller => 'content', :action => 'show_page', :id => '1') + assert_equal ['/page/10', {}], rs.generate(:controller => 'content', :action => 'show_page', :id => 10) + + ctrl = ::Controllers::ContentController + + assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => 1}, rs.recognize_path(%w(page))) + assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => '1'}, rs.recognize_path(%w(page 1))) + assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => '10'}, rs.recognize_path(%w(page 10))) + end + def test_action_expiry assert_equal ['/content', {}], rs.generate({:controller => 'content'}, {:controller => 'content', :action => 'show'}) end |