Merge pull request #44596 from fractaledmind/patch-1
Use #attribute_names in ActiveRecord::Core#inspect
This commit is contained in:
commit
190291dc45
|
@ -695,7 +695,7 @@ module ActiveRecord
|
||||||
# We check defined?(@attributes) not to issue warnings if the object is
|
# We check defined?(@attributes) not to issue warnings if the object is
|
||||||
# allocated but not initialized.
|
# allocated but not initialized.
|
||||||
inspection = if defined?(@attributes) && @attributes
|
inspection = if defined?(@attributes) && @attributes
|
||||||
self.class.attribute_names.filter_map do |name|
|
attribute_names.filter_map do |name|
|
||||||
if _has_attribute?(name)
|
if _has_attribute?(name)
|
||||||
"#{name}: #{attribute_for_inspect(name)}"
|
"#{name}: #{attribute_for_inspect(name)}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -50,6 +50,11 @@ class CoreTest < ActiveRecord::TestCase
|
||||||
assert_equal "NonExistentTable(Table doesn't exist)", NonExistentTable.inspect
|
assert_equal "NonExistentTable(Table doesn't exist)", NonExistentTable.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_inspect_relation_with_virtual_field
|
||||||
|
relation = Topic.limit(1).select("1 as virtual_field")
|
||||||
|
assert_match(/virtual_field: 1/, relation.inspect)
|
||||||
|
end
|
||||||
|
|
||||||
def test_pretty_print_new
|
def test_pretty_print_new
|
||||||
topic = Topic.new
|
topic = Topic.new
|
||||||
actual = +""
|
actual = +""
|
||||||
|
|
Loading…
Reference in New Issue