提交 b33a752f 编写于 作者: R Rafael Mendonça França

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

added one test case and example for ActiveRecord::Base.to_param method
......@@ -81,6 +81,10 @@ module ClassMethods
# 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:
#
......
......@@ -34,6 +34,12 @@ def test_to_param_class_method_truncates
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册