From 5d4a77d324fa30c616d0e05144edc57f10cfb9b5 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 14 Jun 2019 13:25:16 +0200 Subject: Fix TranslationHelper#translate handling of Hash defaults It is sometimes expected of the `translate` methods to return a Hash, for instance it's the case of the `number.format` key. As such users might need to specify a Hash default, e.g. `translate(:'some.format', default: { separator: '.', delimiter: ',' })`. This works as expected with the `I18n.translate` methods, however `TranslationHelper#translate` apply `Array()` on the default value. As a result the default value end up as `[:separator, '.', :delimiter, ',']`. --- actionview/test/template/translation_helper_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionview/test/template/translation_helper_test.rb') 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") -- cgit v1.2.3