Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Base.inspect handles Base itself and abstract_class? Don't use #<Foo …

…...> since that notation's typically used for instances of a class, not the class itself. Closes #8490 [deepblue]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6913 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit d0360a4d5c024c85ecdd7a4eca72256712c4f9d3 1 parent 8158455
@jeremy jeremy authored
View
11 activerecord/lib/active_record/base.rb
@@ -895,9 +895,16 @@ def descends_from_active_record?
end
end
- # Returns a string looking like: #<Post id:integer, title:string, body:text>
+ # 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
View
12 activerecord/test/base_test.rb
@@ -1680,12 +1680,18 @@ def test_to_param_should_return_string
# "expected last count (#{counts.last}) to be <= first count (#{counts.first})"
#end
- def test_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_instance
topic = topics(:first)
- 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 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>), topic.inspect
end
- def test_inspect_new
+ def test_inspect_new_instance
assert_match /Topic id: nil/, Topic.new.inspect
end

0 comments on commit d0360a4

Please sign in to comment.
Something went wrong with that request. Please try again.