aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2019-06-17 13:38:39 -0400
committerGitHub <noreply@github.com>2019-06-17 13:38:39 -0400
commitc65acad0df6b332324c24e725c7d581bd76f9760 (patch)
tree64498e98c2102fd59f2b87dd54a2c2fb0226f8cb
parentc104bfe424e6cebe9c8e85a38515327a6c88b1f8 (diff)
parent5d4a77d324fa30c616d0e05144edc57f10cfb9b5 (diff)
downloadrails-c65acad0df6b332324c24e725c7d581bd76f9760.tar.gz
rails-c65acad0df6b332324c24e725c7d581bd76f9760.tar.bz2
rails-c65acad0df6b332324c24e725c7d581bd76f9760.zip
Merge pull request #36482 from Shopify/fix-translation-helper-default-hash
Fix TranslationHelper#translate handling of Hash defaults
-rw-r--r--actionview/lib/action_view/helpers/translation_helper.rb2
-rw-r--r--actionview/test/template/translation_helper_test.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/translation_helper.rb b/actionview/lib/action_view/helpers/translation_helper.rb
index d5b0a9263f..baa337c62f 100644
--- a/actionview/lib/action_view/helpers/translation_helper.rb
+++ b/actionview/lib/action_view/helpers/translation_helper.rb
@@ -60,7 +60,7 @@ module ActionView
def translate(key, options = {})
options = options.dup
if options.has_key?(:default)
- remaining_defaults = Array(options.delete(:default)).compact
+ remaining_defaults = Array.wrap(options.delete(:default)).compact
options[:default] = remaining_defaults unless remaining_defaults.first.kind_of?(Symbol)
end
diff --git a/actionview/test/template/translation_helper_test.rb b/actionview/test/template/translation_helper_test.rb
index 9afdc3c68f..3475a1dada 100644
--- a/actionview/test/template/translation_helper_test.rb
+++ b/actionview/test/template/translation_helper_test.rb
@@ -121,6 +121,11 @@ class TranslationHelperTest < ActiveSupport::TestCase
I18n.exception_handler = old_exception_handler
end
+ def test_hash_default
+ default = { separator: ".", delimiter: "," }
+ assert_equal default, translate(:'special.number.format', default: default)
+ end
+
def test_translation_returning_an_array
expected = %w(foo bar)
assert_equal expected, translate(:"translations.array")