Don't act destructively on ActiveModel::Name#human options hash. [#5366 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
John Firebaugh 2010-08-12 11:43:10 -07:00 committed by José Valim
parent 308517e913
commit 75a960ca6e
3 changed files with 13 additions and 2 deletions

View File

@ -1,4 +1,5 @@
require 'active_support/inflector'
require 'active_support/core_ext/hash/except'
module ActiveModel
class Name < String
@ -35,10 +36,10 @@ module ActiveModel
klass.model_name.i18n_key
end
defaults << options.delete(:default) if options[:default]
defaults << options[:default] if options[:default]
defaults << @human
options.reverse_merge! :scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults
options = {:scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults}.merge(options.except(:default))
I18n.translate(defaults.shift, options)
end

View File

@ -28,6 +28,10 @@ class NamingTest < ActiveModel::TestCase
def test_partial_path
assert_equal 'post/track_backs/track_back', @model_name.partial_path
end
def test_human
assert_equal 'Track back', @model_name.human
end
end
class NamingWithNamespacedModelInIsolatedNamespaceTest < ActiveModel::TestCase

View File

@ -46,5 +46,11 @@ class ActiveModelI18nTests < ActiveModel::TestCase
I18n.backend.store_translations 'en', :activemodel => {:models => {:person => 'person model'} }
assert_equal 'person model', Child.model_name.human
end
def test_human_does_not_modify_options
options = {:default => 'person model'}
Person.model_name.human(options)
assert_equal({:default => 'person model'}, options)
end
end