aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Firebaugh <john_firebaugh@bigfix.com>2010-08-12 11:43:10 -0700
committerJosé Valim <jose.valim@gmail.com>2010-09-25 10:59:54 +0200
commit75a960ca6e38ae68fd55c034272102077fd95afa (patch)
treef91226095842303acd0bf049245fd74d38a2e258
parent308517e913ef1e8d9f13e023bc450374b5ed780a (diff)
downloadrails-75a960ca6e38ae68fd55c034272102077fd95afa.tar.gz
rails-75a960ca6e38ae68fd55c034272102077fd95afa.tar.bz2
rails-75a960ca6e38ae68fd55c034272102077fd95afa.zip
Don't act destructively on ActiveModel::Name#human options hash. [#5366 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
-rw-r--r--activemodel/lib/active_model/naming.rb5
-rw-r--r--activemodel/test/cases/naming_test.rb4
-rw-r--r--activemodel/test/cases/translation_test.rb6
3 files changed, 13 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb
index 0706df4b59..fc2abacb6d 100644
--- a/activemodel/lib/active_model/naming.rb
+++ b/activemodel/lib/active_model/naming.rb
@@ -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
diff --git a/activemodel/test/cases/naming_test.rb b/activemodel/test/cases/naming_test.rb
index c6b663ef93..40ce4c0e2d 100644
--- a/activemodel/test/cases/naming_test.rb
+++ b/activemodel/test/cases/naming_test.rb
@@ -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
diff --git a/activemodel/test/cases/translation_test.rb b/activemodel/test/cases/translation_test.rb
index d6942a5475..ac2e56321e 100644
--- a/activemodel/test/cases/translation_test.rb
+++ b/activemodel/test/cases/translation_test.rb
@@ -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