Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@seckar seckar authored
View
2  actionpack/lib/action_controller/routing.rb
@@ -99,7 +99,7 @@ def initialize(key, options = {})
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
View
22 actionpack/test/controller/routing_test.rb
@@ -705,6 +705,10 @@ def test_paths_escaped
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 @@ def test_backwards
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
Please sign in to comment.
Something went wrong with that request. Please try again.