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

Merge pull request #42832 from lulalala/slim-errors-inspect

Slimmer ActiveModel::Errors#inspect message
This commit is contained in:
Jean Boussier 2021-07-23 09:05:08 +02:00 committed by GitHub
commit 8512118f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View file

@ -39,5 +39,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