From a5d588875f22af852324f57aedef00b1aa345c7b Mon Sep 17 00:00:00 2001 From: Kuldeep Aggarwal Date: Fri, 15 Nov 2013 20:05:17 +0530 Subject: [PATCH] added one test case and example for ActiveRecord::Base.to_param method --- activerecord/lib/active_record/integration.rb | 4 ++++ activerecord/test/cases/integration_test.rb | 6 ++++++ 2 files changed, 10 insertions(+) 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