From 4a3ec21b6261374ad58f3bc337fc8a547b6c490d Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Fri, 8 Jul 2005 08:45:51 +0000 Subject: 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 --- actionpack/lib/action_controller/routing.rb | 2 +- actionpack/test/controller/routing_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3