mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #44596 from fractaledmind/patch-1
Use #attribute_names in ActiveRecord::Core#inspect
This commit is contained in:
commit
190291dc45
2 changed files with 6 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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 = +""
|
||||
|
|
Loading…
Reference in a new issue