diff options
author | Tsutomu Kuroda <t-kuroda@oiax.jp> | 2012-04-14 18:00:54 +0900 |
---|---|---|
committer | Tsutomu Kuroda <t-kuroda@oiax.jp> | 2012-05-16 08:39:48 +0900 |
commit | b0e2fc843b555f94a4472ed50b337dc5048c8b8c (patch) | |
tree | 42288e769a0fa86110930513a7caa113fdc51225 /activemodel/test | |
parent | 7994496ab4127cf15323563acd55170b9d35821a (diff) | |
download | rails-b0e2fc843b555f94a4472ed50b337dc5048c8b8c.tar.gz rails-b0e2fc843b555f94a4472ed50b337dc5048c8b8c.tar.bz2 rails-b0e2fc843b555f94a4472ed50b337dc5048c8b8c.zip |
Fix human attribute_name to handle deeply nested attributes
When a model nests another model that also nests yet another model
using accepts_nested_attributes_for method, its Errors object can
have an attribute name with "contacts.addresses.street" style.
In this case, the dots within the namespace should be substituted
with slashes so that we can provide the translation under the
"activemodel.attributes.person/contacts/addresses.street" key.
This commit is related to #3859.
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/translation_test.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/activemodel/test/cases/translation_test.rb b/activemodel/test/cases/translation_test.rb index 4999583802..fd833cdd06 100644 --- a/activemodel/test/cases/translation_test.rb +++ b/activemodel/test/cases/translation_test.rb @@ -56,6 +56,11 @@ class ActiveModelI18nTests < ActiveModel::TestCase assert_equal 'person gender attribute', Person::Gender.human_attribute_name('attribute') end + def test_translated_deeply_nested_model_attributes + I18n.backend.store_translations 'en', :activemodel => {:attributes => {:"person/contacts/addresses" => {:street => 'Deeply Nested Address Street'}}} + assert_equal 'Deeply Nested Address Street', Person.human_attribute_name('contacts.addresses.street') + end + def test_translated_nested_model_attributes I18n.backend.store_translations 'en', :activemodel => {:attributes => {:"person/addresses" => {:street => 'Person Address Street'}}} assert_equal 'Person Address Street', Person.human_attribute_name('addresses.street') |