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:
parent
a34d64d82e
commit
1523838567
3 changed files with 16 additions and 0 deletions
|
@ -14,5 +14,8 @@
|
||||||
|
|
||||||
*Lukas Pokorny*
|
*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.
|
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")
|
add_from_legacy_details_hash(data["details"]) if data.key?("details")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inspect # :nodoc:
|
||||||
|
inspection = @errors.inspect
|
||||||
|
|
||||||
|
"#<#{self.class.name} #{inspection}>"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def normalize_arguments(attribute, type, **options)
|
def normalize_arguments(attribute, type, **options)
|
||||||
# Evaluate proc first
|
# Evaluate proc first
|
||||||
|
|
|
@ -880,4 +880,11 @@ class ErrorsTest < ActiveModel::TestCase
|
||||||
assert_equal({}, errors.messages)
|
assert_equal({}, errors.messages)
|
||||||
assert_equal({}, errors.details)
|
assert_equal({}, errors.details)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "inspect" do
|
||||||
|
errors = ActiveModel::Errors.new(Person.new)
|
||||||
|
errors.add(:base)
|
||||||
|
|
||||||
|
assert_equal(%(#<ActiveModel::Errors [#{errors.first.inspect}]>), errors.inspect)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue