From 45e242f451e818d81514c656bc74947e74ed7ed2 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 16 Mar 2010 17:08:09 -0300 Subject: [PATCH] translation method of TranslationHelper module returns always SafeBuffer [#4194 status:resolved] --- .../lib/action_view/helpers/translation_helper.rb | 2 +- .../test/fixtures/test/array_translation.erb | 1 + .../test/template/translation_helper_test.rb | 9 ++++++++- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 actionpack/test/fixtures/test/array_translation.erb diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index e44a985..185009c 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -13,7 +13,7 @@ module ActionView def translate(key, options = {}) options[:raise] = true translation = I18n.translate(scope_key_by_partial(key), options) - translation.respond_to?(:html_safe) ? translation.html_safe : translation + (translation.respond_to?(:join) ? translation.join : translation).html_safe rescue I18n::MissingTranslationData => e keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope]) content_tag('span', keys.join(', '), :class => 'translation_missing') diff --git a/actionpack/test/fixtures/test/array_translation.erb b/actionpack/test/fixtures/test/array_translation.erb new file mode 100644 index 0000000..12c0763 --- /dev/null +++ b/actionpack/test/fixtures/test/array_translation.erb @@ -0,0 +1 @@ +<%= t(['foo', 'bar']) %> \ No newline at end of file diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index 0a9efc7..d168a60 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -20,7 +20,14 @@ class TranslationHelperTest < Test::Unit::TestCase def test_translation_of_an_array I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(["foo", "bar"]) - assert_equal ["foo", "bar"], translate(["foo", "bar"]) + assert_equal "foobar", translate(["foo", "bar"]) + end + + def test_translation_of_an_array_with_html + expected = 'foobar' + I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(['foo', 'bar']) + @view = ActionView::Base.new(ActionController::Base.view_paths, {}) + assert_equal expected, @view.render(:file => "test/array_translation") end def test_delegates_localize_to_i18n -- 1.7.0