1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Slimmer ActiveModel::Errors#inspect

Only show @errors array and hide @base
This commit is contained in:
lulalala 2021-07-21 20:56:28 +08:00
parent a34d64d82e
commit 1523838567
3 changed files with 16 additions and 0 deletions

View file

@ -14,5 +14,8 @@
*Lukas Pokorny*
* Make ActiveModel::Errors#inspect slimmer for readability
*lulalala*
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activemodel/CHANGELOG.md) for previous changes.

View file

@ -571,6 +571,12 @@ module ActiveModel
add_from_legacy_details_hash(data["details"]) if data.key?("details")
end
def inspect # :nodoc:
inspection = @errors.inspect
"#<#{self.class.name} #{inspection}>"
end
private
def normalize_arguments(attribute, type, **options)
# Evaluate proc first

View file

@ -880,4 +880,11 @@ class ErrorsTest < ActiveModel::TestCase
assert_equal({}, errors.messages)
assert_equal({}, errors.details)
end
test "inspect" do
errors = ActiveModel::Errors.new(Person.new)
errors.add(:base)
assert_equal(%(#<ActiveModel::Errors [#{errors.first.inspect}]>), errors.inspect)
end
end