diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-11-15 06:57:31 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-11-15 06:57:31 -0800 |
commit | b33a752f990fed0df8f2187ae98556104d8b683b (patch) | |
tree | 2e011943f49c22cdb472a97d170db0ef8a80bdfa | |
parent | 5f1347dd1f4517725829b20cae8aee3bc6602f96 (diff) | |
parent | a5d588875f22af852324f57aedef00b1aa345c7b (diff) | |
download | rails-b33a752f990fed0df8f2187ae98556104d8b683b.tar.gz rails-b33a752f990fed0df8f2187ae98556104d8b683b.tar.bz2 rails-b33a752f990fed0df8f2187ae98556104d8b683b.zip |
Merge pull request #12900 from kuldeepaggarwal/f-to-param
added one test case and example for ActiveRecord::Base.to_param method
-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 |