Permalink
Browse files

default could be a symbol here so attribute.to_s.humanize should be t…

…he final option
  • Loading branch information...
1 parent 20ba81e commit 33b0a30fcc5694d26034bc74ed61e34edecbfbc4 @spastorino spastorino committed Dec 5, 2010
Showing with 6 additions and 1 deletion.
  1. +2 −1 activemodel/lib/active_model/translation.rb
  2. +4 −0 activemodel/test/cases/translation_test.rb
@@ -48,7 +48,8 @@ def human_attribute_name(attribute, options = {})
end
defaults << :"attributes.#{attribute}"
- defaults << (options[:default] ? options.delete(:default) : attribute.to_s.humanize)
+ defaults << options.delete(:default) if options[:default]
+ defaults << attribute.to_s.humanize
options.reverse_merge! :count => 1, :default => defaults
I18n.translate(defaults.shift, options)
@@ -25,6 +25,10 @@ def test_translated_model_attributes_falling_back_to_default
assert_equal 'Name', Person.human_attribute_name('name')
end
+ def test_translated_model_attributes_using_default_option_as_symbol_and_falling_back_to_default
+ assert_equal 'Name', Person.human_attribute_name('name', :default => :default_name)
+ end
+
def test_translated_model_attributes_with_symbols
I18n.backend.store_translations 'en', :activemodel => {:attributes => {:person => {:name => 'person name attribute'} } }
assert_equal 'person name attribute', Person.human_attribute_name(:name)

0 comments on commit 33b0a30

Please sign in to comment.