Permalink
Browse files

Merge pull request #5843 from kuroda/translation_of_deeply_nested_mod…

…el_attributes

Fix human attribute_name to handle deeply nested attributes
  • Loading branch information...
2 parents 70bc0d7 + b0e2fc8 commit 555d8152c79eabc575413a0ddd199ac8304d776b @josevalim josevalim committed May 30, 2012
Showing with 7 additions and 2 deletions.
  1. +2 −2 activemodel/lib/active_model/translation.rb
  2. +5 −0 activemodel/test/cases/translation_test.rb
@@ -42,9 +42,9 @@ def lookup_ancestors
# Specify +options+ with additional translating options.
def human_attribute_name(attribute, options = {})
options = { :count => 1 }.merge!(options)
- parts = attribute.to_s.split(".", 2)
+ parts = attribute.to_s.split(".")
attribute = parts.pop
- namespace = parts.pop
+ namespace = parts.join("/") unless parts.empty?
attributes_scope = "#{self.i18n_scope}.attributes"
if namespace
@@ -56,6 +56,11 @@ def test_translated_model_attributes_with_attribute_matching_namespaced_model_na
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')

0 comments on commit 555d815

Please sign in to comment.