diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 94b3ac1057..bf5ee1854d 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1814,7 +1814,7 @@ module ActiveRecord #:nodoc: # Format attributes nicely for inspect. 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) if value.is_a?(String) && value.length > 50 diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 60e48c763b..02ca84e782 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1651,6 +1651,10 @@ class BasicsTest < Test::Unit::TestCase assert_equal topic.inspect, %(#) end + def test_inspect_new + assert_match /Topic id: nil/, Topic.new.inspect + end + def test_attribute_for_inspect 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!)