diff options
author | Kuldeep Aggarwal <kd.engineer@yahoo.co.in> | 2013-11-15 20:05:17 +0530 |
---|---|---|
committer | Kuldeep Aggarwal <kd.engineer@yahoo.co.in> | 2013-11-15 20:05:17 +0530 |
commit | a5d588875f22af852324f57aedef00b1aa345c7b (patch) | |
tree | a899a583edefc0b0a3520d4f3730b061e93be167 /activerecord | |
parent | 81475534ed9e2e1b7bade50f1e1099975e385a46 (diff) | |
download | rails-a5d588875f22af852324f57aedef00b1aa345c7b.tar.gz rails-a5d588875f22af852324f57aedef00b1aa345c7b.tar.bz2 rails-a5d588875f22af852324f57aedef00b1aa345c7b.zip |
added one test case and example for ActiveRecord::Base.to_param method
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/integration.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/integration_test.rb | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/integration.rb b/activerecord/lib/active_record/integration.rb index 951db5b756..f8aa0c55db 100644 --- a/activerecord/lib/active_record/integration.rb +++ b/activerecord/lib/active_record/integration.rb @@ -81,6 +81,10 @@ module ActiveRecord # user.id # => 123 # user_path(user) # => "/users/123-fancy-pants" # + # user = User.find_by(name: 'David HeinemeierHansson') + # user.id # => 125 + # user_path(user) # => "/users/125-david" + # # Because the generated param begins with the record's +id+, it is # suitable for passing to +find+. In a controller, for example: # diff --git a/activerecord/test/cases/integration_test.rb b/activerecord/test/cases/integration_test.rb index 8097f6e36e..07ffcef875 100644 --- a/activerecord/test/cases/integration_test.rb +++ b/activerecord/test/cases/integration_test.rb @@ -34,6 +34,12 @@ class IntegrationTest < ActiveRecord::TestCase assert_equal '4-a-a-a-a-a-a-a-a-a', firm.to_param end + def test_to_param_class_method_truncates_edge_case + firm = Firm.find(4) + firm.name = 'David HeinemeierHansson' + assert_equal '4-david', firm.to_param + end + def test_to_param_class_method_squishes firm = Firm.find(4) firm.name = "ab \n" * 100 |