From dff19f7be2584d9eaa869de14a919aa70d029d92 Mon Sep 17 00:00:00 2001 From: Tsutomu Kuroda Date: Mon, 5 Dec 2011 22:57:47 +0900 Subject: Fix human_attribute_name to handle names with dots Nested I18n namespace lookup under activerecord.models is deprecated now (c19bd4f). But when a model uses accepts_nested_attributes_for, its Errors object can have an attribute name with "addresses.street" style. In this case, the dots should be substituted with slashes so that we can provide the translation under the "activemodel.attributes.person.addresses/street" key. --- activemodel/test/cases/translation_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activemodel/test') diff --git a/activemodel/test/cases/translation_test.rb b/activemodel/test/cases/translation_test.rb index 1b1d972d5c..c3d60d6c8b 100644 --- a/activemodel/test/cases/translation_test.rb +++ b/activemodel/test/cases/translation_test.rb @@ -56,6 +56,16 @@ class ActiveModelI18nTests < ActiveModel::TestCase assert_equal 'person gender attribute', Person::Gender.human_attribute_name('attribute') end + def test_translated_nested_model_attributes + I18n.backend.store_translations 'en', :activemodel => {:attributes => {:person => {:"addresses/street" => 'Street'}}} + assert_equal 'Street', Person.human_attribute_name('addresses.street') + end + + def test_translated_nested_model_attributes_with_deprecated_lookup_style + I18n.backend.store_translations 'en', :activemodel => {:attributes => {:person => {:addresses => {:street => 'Street'}}}} + assert_equal 'Street', Person.human_attribute_name('addresses.street') + end + def test_translated_model_names I18n.backend.store_translations 'en', :activemodel => {:models => {:person => 'person model'} } assert_equal 'person model', Person.model_name.human -- cgit v1.2.3