Skip to content

Commit a5d1e10

Browse files
authored
Merge pull request rails#53014 from fatkodima/fix-inspect-for-singleton-classes
Fix `#inspect` for ActiveRecord singleton classes
2 parents 31818ed + 43490d0 commit a5d1e10

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

activerecord/lib/active_record/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def inspection_filter # :nodoc:
350350

351351
# Returns a string like 'Post(id:integer, title:string, body:text)'
352352
def inspect # :nodoc:
353-
if self == Base
353+
if self == Base || singleton_class?
354354
super
355355
elsif abstract_class?
356356
"#{super}(abstract)"

activerecord/test/cases/core_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def test_inspect_new_instance
4747
assert_match(/Topic id: nil/, Topic.new.inspect)
4848
end
4949

50+
def test_inspect_singleton_instance
51+
assert_match(/#<Class:#<Topic:\w+>>/, Topic.new.singleton_class.inspect)
52+
end
53+
5054
def test_inspect_limited_select_instance
5155
Topic.stub(:attributes_for_inspect, [:id, :title]) do
5256
assert_equal %(#<Topic id: 1>), Topic.all.merge!(select: "id", where: "id = 1").first.inspect

0 commit comments

Comments
 (0)