aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
diff options
context:
space:
mode:
authorEdouard CHIN <edouard.chin@shopify.com>2019-07-10 23:30:44 +0200
committerEdouard CHIN <edouard.chin@shopify.com>2019-07-16 14:28:38 +0200
commitd204a09df21ce3578081108936a57707b5ece9b8 (patch)
tree48d3e64b8c480e13a6c538ff1cf84d50d713131c /activemodel/test
parentb677adede027eefed41f6b37096df7bbc4eb3d38 (diff)
downloadrails-d204a09df21ce3578081108936a57707b5ece9b8.tar.gz
rails-d204a09df21ce3578081108936a57707b5ece9b8.tar.bz2
rails-d204a09df21ce3578081108936a57707b5ece9b8.zip
Switch to use `class_attribute`:
- Since `ActiveModel::Error` can now be inherited by `ActiveModel::NestedError`, when the latter generates a `full_message`, the `i18n_customize_full_message` accessor set in the parent class is not set. This commit fixes that by using a `class_attribute` instead.
Diffstat (limited to 'activemodel/test')
-rw-r--r--activemodel/test/cases/validations/i18n_validation_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/i18n_validation_test.rb b/activemodel/test/cases/validations/i18n_validation_test.rb
index ea5b335f44..c81649f493 100644
--- a/activemodel/test/cases/validations/i18n_validation_test.rb
+++ b/activemodel/test/cases/validations/i18n_validation_test.rb
@@ -59,6 +59,19 @@ class I18nValidationTest < ActiveModel::TestCase
assert_equal "Name test cannot be blank", person.errors.full_message(:name_test, "cannot be blank")
end
+ def test_errors_full_messages_on_nested_error_uses_attribute_format
+ ActiveModel::Error.i18n_customize_full_message = true
+ I18n.backend.store_translations("en", activemodel: {
+ errors: { models: { person: { attributes: { gender: "Gender" } } } },
+ attributes: { "person/contacts": { gender: "Gender" } }
+ })
+
+ person = person_class.new
+ error = ActiveModel::Error.new(person, :gender, "can't be blank")
+ person.errors.import(error, attribute: "person[0].contacts.gender")
+ assert_equal ["Gender can't be blank"], person.errors.full_messages
+ end
+
def test_errors_full_messages_uses_attribute_format
ActiveModel::Error.i18n_customize_full_message = true