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

Fix #inspect for new records. Closes #8405.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6782 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2007-05-19 01:35:19 +00:00
parent 81ee044fda
commit a995b9cde0
2 changed files with 5 additions and 1 deletions

View file

@ -1814,7 +1814,7 @@ module ActiveRecord #:nodoc:
# Format attributes nicely for inspect. # Format attributes nicely for inspect.
def attribute_for_inspect(attr_name) def attribute_for_inspect(attr_name)
raise "Attribute not present #{attr_name}" unless has_attribute?(attr_name) raise "Attribute not present #{attr_name}" unless has_attribute?(attr_name) || new_record?
value = read_attribute(attr_name) value = read_attribute(attr_name)
if value.is_a?(String) && value.length > 50 if value.is_a?(String) && value.length > 50

View file

@ -1651,6 +1651,10 @@ class BasicsTest < Test::Unit::TestCase
assert_equal topic.inspect, %(#<Topic id: 1, title: "The First Topic", author_name: "David", author_email_address: "david@loudthinking.com", written_on: "#{topic.written_on.to_s(:db)}", bonus_time: "#{topic.bonus_time.to_s(:db)}", last_read: "#{topic.last_read.to_s(:db)}", content: "Have a nice day", approved: false, replies_count: 1, parent_id: nil, type: nil>) assert_equal topic.inspect, %(#<Topic id: 1, title: "The First Topic", author_name: "David", author_email_address: "david@loudthinking.com", written_on: "#{topic.written_on.to_s(:db)}", bonus_time: "#{topic.bonus_time.to_s(:db)}", last_read: "#{topic.last_read.to_s(:db)}", content: "Have a nice day", approved: false, replies_count: 1, parent_id: nil, type: nil>)
end end
def test_inspect_new
assert_match /Topic id: nil/, Topic.new.inspect
end
def test_attribute_for_inspect def test_attribute_for_inspect
t = topics(:first) t = topics(:first)
t.content = %(This is some really long content, longer than 50 characters, so I can test that text is truncated correctly by the new ActiveRecord::Base#inspect method! Yay! BOOM!) t.content = %(This is some really long content, longer than 50 characters, so I can test that text is truncated correctly by the new ActiveRecord::Base#inspect method! Yay! BOOM!)