aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-27 11:49:34 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-27 11:49:34 -0300
commit85c49f5a6431b36c9c36c367b5d9edaa8b79f733 (patch)
treea1f98d7eac044b6d586ae2eadda01917286b811e /actionview
parentf3ae917be46a2fc4c38691a957330310ae7b3b29 (diff)
parent362557eb4169a541063468b489931648665f1fa3 (diff)
downloadrails-85c49f5a6431b36c9c36c367b5d9edaa8b79f733.tar.gz
rails-85c49f5a6431b36c9c36c367b5d9edaa8b79f733.tar.bz2
rails-85c49f5a6431b36c9c36c367b5d9edaa8b79f733.zip
Merge pull request #19102 from ulissesalmeida/fix-regression-default-translation
Fix regression when passing a value different of String.
Diffstat (limited to 'actionview')
-rw-r--r--actionview/CHANGELOG.md5
-rw-r--r--actionview/lib/action_view/helpers/translation_helper.rb6
-rw-r--r--actionview/test/template/translation_helper_test.rb5
3 files changed, 15 insertions, 1 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index 8f47171e62..101f1263d9 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Fixed the translation helper method to accept different default values types
+ besides String.
+
+ *Ulisses Almeida*
+
* Collection rendering automatically caches and fetches multiple partials.
Collections rendered as:
diff --git a/actionview/lib/action_view/helpers/translation_helper.rb b/actionview/lib/action_view/helpers/translation_helper.rb
index 342361217c..24b633c5bb 100644
--- a/actionview/lib/action_view/helpers/translation_helper.rb
+++ b/actionview/lib/action_view/helpers/translation_helper.rb
@@ -37,8 +37,12 @@ module ActionView
# you know what kind of output to expect when you call translate in a template.
def translate(key, options = {})
options = options.dup
+ has_default = options.has_key?(:default)
remaining_defaults = Array(options.delete(:default))
- options[:default] = remaining_defaults.shift if remaining_defaults.first.kind_of? String
+
+ if has_default && !remaining_defaults.first.kind_of?(Symbol)
+ options[:default] = remaining_defaults.shift
+ end
# If the user has explicitly decided to NOT raise errors, pass that option to I18n.
# Otherwise, tell I18n to raise an exception, which we rescue further in this method.
diff --git a/actionview/test/template/translation_helper_test.rb b/actionview/test/template/translation_helper_test.rb
index 8fde478ac9..ef4d13efa7 100644
--- a/actionview/test/template/translation_helper_test.rb
+++ b/actionview/test/template/translation_helper_test.rb
@@ -180,6 +180,11 @@ class TranslationHelperTest < ActiveSupport::TestCase
assert_equal 'A Generic String', translation
end
+ def test_translate_with_object_default
+ translation = translate(:'translations.missing', default: 123)
+ assert_equal 123, translation
+ end
+
def test_translate_with_array_of_string_defaults
translation = translate(:'translations.missing', default: ['A Generic String', 'Second generic string'])
assert_equal 'A Generic String', translation