From e5fc5aaffe0d97b73678d7edfcaca222f01aba69 Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Mon, 19 Jun 2006 16:45:34 +0000 Subject: [PATCH] Change AR::Base#to_param to return a String instead of a Fixnum. Closes #5320. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4459 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ activerecord/lib/active_record/base.rb | 4 ++-- activerecord/test/base_test.rb | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index b14fb50662..dc18983ff6 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Change AR::Base#to_param to return a String instead of a Fixnum. Closes #5320. [Nicholas Seckar] + * Use explicit delegation instead of method aliasing for AR::Base.to_param -> AR::Base.id. #5299 (skaes@web.de) * Refactored ActiveRecord::Base.to_xml to become a delegate for XmlSerializer, which restores sanity to the mega method. This refactoring also reinstates the opinions that type="string" is redundant and ugly and nil-differentiation is not a concern of serialization [DHH] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index dee460d9c5..fe528f514c 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1410,8 +1410,8 @@ module ActiveRecord #:nodoc: # Enables Active Record objects to be used as URL parameters in Action Pack automatically. def to_param - # can't use alias_method here, because method 'id' optimizes itself on the fly - id + # We can't use alias_method here, because method 'id' optimizes itself on the fly. + id.to_s if id # Be sure to stringify the id for routes end def id_before_type_cast #:nodoc: diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 44b7aea942..2cbc2cfd2b 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1316,6 +1316,10 @@ class BasicsTest < Test::Unit::TestCase assert_equal 'ActiveRecord::Person', ActiveRecord::Base.send(:type_name_with_module, 'Person') assert_equal '::Person', ActiveRecord::Base.send(:type_name_with_module, '::Person') end + + def test_to_param_should_return_string + assert_kind_of String, Client.find(:first).to_param + end # FIXME: this test ought to run, but it needs to run sandboxed so that it # doesn't b0rk the current test environment by undefing everything.