Permalink
Browse files

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

added one test case and example for ActiveRecord::Base.to_param method
  • Loading branch information...
rafaelfranca committed Nov 15, 2013
2 parents 5f1347d + a5d5888 commit b33a752f990fed0df8f2187ae98556104d8b683b
Showing with 10 additions and 0 deletions.
  1. +4 −0 activerecord/lib/active_record/integration.rb
  2. +6 −0 activerecord/test/cases/integration_test.rb
@@ -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

0 comments on commit b33a752

Please sign in to comment.