1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #12900 from kuldeepaggarwal/f-to-param

added one test case and example for ActiveRecord::Base.to_param method
This commit is contained in:
Rafael Mendonça França 2013-11-15 06:57:31 -08:00
commit b33a752f99
2 changed files with 10 additions and 0 deletions

View file

@ -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:
#

View file

@ -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