diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index 9138bcabad..d7513dce8a 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -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. diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 2046ee2d21..e4e4b6cf1d 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -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 diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 91cebe2e5e..b9f564fb4d 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -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(%(#), errors.inspect) + end end