aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations/i18n_validation_test.rb
diff options
context:
space:
mode:
authorMartin Larochelle <martin.larochelle@shopify.com>2018-05-17 08:39:31 -0400
committerMartin Larochelle <martin.larochelle@shopify.com>2018-05-22 16:31:30 -0400
commit7d09874a71ecceb929a99f914b703adc16d80e83 (patch)
tree55f840e2ea961ceb203c335729ba4d4e1cb650a5 /activemodel/test/cases/validations/i18n_validation_test.rb
parent5003d5996a3d29d6614ccf714ad05f911aa30cff (diff)
downloadrails-7d09874a71ecceb929a99f914b703adc16d80e83.tar.gz
rails-7d09874a71ecceb929a99f914b703adc16d80e83.tar.bz2
rails-7d09874a71ecceb929a99f914b703adc16d80e83.zip
Allow to override the full_message error format
Diffstat (limited to 'activemodel/test/cases/validations/i18n_validation_test.rb')
-rw-r--r--activemodel/test/cases/validations/i18n_validation_test.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/i18n_validation_test.rb b/activemodel/test/cases/validations/i18n_validation_test.rb
index 9cfe189d0e..ea462d9e07 100644
--- a/activemodel/test/cases/validations/i18n_validation_test.rb
+++ b/activemodel/test/cases/validations/i18n_validation_test.rb
@@ -42,6 +42,42 @@ class I18nValidationTest < ActiveModel::TestCase
assert_equal ["Field Name empty"], @person.errors.full_messages
end
+ def test_errors_full_messages_uses_attribute_format
+ I18n.backend.store_translations("en", activemodel: {
+ errors: { models: { person: { attributes: { name: { format: "%{message}" } } } } } })
+
+ person = Person.new
+ assert_equal "cannot be blank", person.errors.full_message(:name, "cannot be blank")
+ assert_equal "Name test cannot be blank", person.errors.full_message(:name_test, "cannot be blank")
+ end
+
+ def test_errors_full_messages_uses_model_format
+ I18n.backend.store_translations("en", activemodel: {
+ errors: { models: { person: { format: "%{message}" } } } })
+
+ person = Person.new
+ assert_equal "cannot be blank", person.errors.full_message(:name, "cannot be blank")
+ assert_equal "cannot be blank", person.errors.full_message(:name_test, "cannot be blank")
+ end
+
+ def test_errors_full_messages_uses_deeply_nested_model_attributes_format
+ I18n.backend.store_translations("en", activemodel: {
+ errors: { models: { 'person/contacts/addresses': { attributes: { street: { format: "%{message}" } } } } } })
+
+ person = Person.new
+ assert_equal "cannot be blank", person.errors.full_message(:'contacts/addresses.street', "cannot be blank")
+ assert_equal "Contacts/addresses country cannot be blank", person.errors.full_message(:'contacts/addresses.country', "cannot be blank")
+ end
+
+ def test_errors_full_messages_uses_deeply_nested_model_model_format
+ I18n.backend.store_translations("en", activemodel: {
+ errors: { models: { 'person/contacts/addresses': { format: "%{message}" } } } })
+
+ person = Person.new
+ assert_equal "cannot be blank", person.errors.full_message(:'contacts/addresses.street', "cannot be blank")
+ assert_equal "cannot be blank", person.errors.full_message(:'contacts/addresses.country', "cannot be blank")
+ end
+
# ActiveModel::Validations
# A set of common cases for ActiveModel::Validations message generation that