diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index b838b1cdc0..e1f3dce7ce 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -895,9 +895,16 @@ module ActiveRecord #:nodoc: end end - # Returns a string looking like: # + # Returns a string like 'Post id:integer, title:string, body:text' def inspect - "#<#{name} #{columns.collect { |c| "#{c.name}: #{c.type}" }.join(", ")}>" + if self == Base + super + elsif abstract_class? + "#{super}(abstract)" + else + attr_list = columns.map { |c| "#{c.name}: #{c.type}" } * ', ' + "#{super}(#{attr_list})" + end end diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index d74a7b82b5..a64f933f37 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1680,12 +1680,18 @@ class BasicsTest < Test::Unit::TestCase # "expected last count (#{counts.last}) to be <= first count (#{counts.first})" #end - def test_inspect - topic = topics(:first) - assert_equal topic.inspect, %(#) + def test_inspect_class + assert_equal 'ActiveRecord::Base', ActiveRecord::Base.inspect + assert_equal 'LoosePerson(abstract)', LoosePerson.inspect + assert_match(/^Topic\(id: integer, title: string/, Topic.inspect) end - def test_inspect_new + def test_inspect_instance + topic = topics(:first) + assert_equal %(#), topic.inspect + end + + def test_inspect_new_instance assert_match /Topic id: nil/, Topic.new.inspect end