Merge pull request #44596 from fractaledmind/patch-1

Use #attribute_names in ActiveRecord::Core#inspect
This commit is contained in:
Jean Boussier 2022-03-10 14:27:44 +01:00 committed by GitHub
commit 190291dc45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -695,7 +695,7 @@ module ActiveRecord
# We check defined?(@attributes) not to issue warnings if the object is
# allocated but not initialized.
inspection = if defined?(@attributes) && @attributes
self.class.attribute_names.filter_map do |name|
attribute_names.filter_map do |name|
if _has_attribute?(name)
"#{name}: #{attribute_for_inspect(name)}"
end

View File

@ -50,6 +50,11 @@ class CoreTest < ActiveRecord::TestCase
assert_equal "NonExistentTable(Table doesn't exist)", NonExistentTable.inspect
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
topic = Topic.new
actual = +""