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:
commit
b33a752f99
2 changed files with 10 additions and 0 deletions
|
@ -81,6 +81,10 @@ module ActiveRecord
|
||||||
# user.id # => 123
|
# user.id # => 123
|
||||||
# user_path(user) # => "/users/123-fancy-pants"
|
# 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
|
# Because the generated param begins with the record's +id+, it is
|
||||||
# suitable for passing to +find+. In a controller, for example:
|
# suitable for passing to +find+. In a controller, for example:
|
||||||
#
|
#
|
||||||
|
|
|
@ -34,6 +34,12 @@ class IntegrationTest < ActiveRecord::TestCase
|
||||||
assert_equal '4-a-a-a-a-a-a-a-a-a', firm.to_param
|
assert_equal '4-a-a-a-a-a-a-a-a-a', firm.to_param
|
||||||
end
|
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
|
def test_to_param_class_method_squishes
|
||||||
firm = Firm.find(4)
|
firm = Firm.find(4)
|
||||||
firm.name = "ab \n" * 100
|
firm.name = "ab \n" * 100
|
||||||
|
|
Loading…
Reference in a new issue