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:
commit
8512118f43
3 changed files with 16 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue