Permalink
Browse files

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

… state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 308517e commit 75a960ca6e38ae68fd55c034272102077fd95afa John Firebaugh committed with josevalim Aug 12, 2010
@@ -1,4 +1,5 @@
require 'active_support/inflector'
+require 'active_support/core_ext/hash/except'
module ActiveModel
class Name < String
@@ -35,10 +36,10 @@ def human(options={})
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
@@ -28,6 +28,10 @@ def test_collection
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
@@ -46,5 +46,11 @@ def test_translated_model_names_with_ancestors_fallback
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

0 comments on commit 75a960c

Please sign in to comment.