diff options
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 89c3d1b7f4..0837e9db96 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -528,6 +528,24 @@ class ErrorsTest < ActiveModel::TestCase assert_equal({ name: [{ error: :invalid }] }, person.errors.details) end + test "details retains original type as error" do + errors = ActiveModel::Errors.new(Person.new) + errors.add(:name, "cannot be nil") + errors.add("foo", "bar") + errors.add(:baz, nil) + errors.add(:age, :invalid, count: 3, message: "%{count} is too low") + + assert_equal( + { + name: [{ error: "cannot be nil" }], + foo: [{ error: "bar" }], + baz: [{ error: nil }], + age: [{ error: :invalid, count: 3 }] + }, + errors.details + ) + end + test "group_by_attribute" do person = Person.new error = person.errors.add(:name, :invalid, message: "is bad") |