From 734c71ca4785b6a8ec178efcb97d102b4ef186ff Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 16 Mar 2010 19:59:04 -0300 Subject: [PATCH] scope_key_by_partial fix for Ruby 1.9 when there's virtual_path --- .../lib/action_view/helpers/translation_helper.rb | 5 +++-- .../fixtures/test/scoped_array_translation.erb | 1 + .../test/template/translation_helper_test.rb | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 actionpack/test/fixtures/test/scoped_array_translation.erb diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index 185009c..9296622 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -29,8 +29,9 @@ module ActionView private def scope_key_by_partial(key) - if (key.respond_to?(:join) ? key.join : key.to_s).first == "." - template.path_without_format_and_extension.gsub(%r{/_?}, ".") + key.to_s + strkey = key.respond_to?(:join) ? key.join : key.to_s + if strkey.first == "." + template.path_without_format_and_extension.gsub(%r{/_?}, ".") + strkey else key end diff --git a/actionpack/test/fixtures/test/scoped_array_translation.erb b/actionpack/test/fixtures/test/scoped_array_translation.erb new file mode 100644 index 0000000..0a0c79f --- /dev/null +++ b/actionpack/test/fixtures/test/scoped_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 d168a60..24640e4 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -41,4 +41,10 @@ class TranslationHelperTest < Test::Unit::TestCase I18n.expects(:translate).with("people.index.foo", :locale => 'en', :raise => true).returns("") translate ".foo", :locale => 'en' end + + def test_scoping_by_partial_of_an_array + I18n.expects(:translate).with("test.scoped_array_translation.foo.bar", :raise => true).returns(["foo", "bar"]) + @view = ActionView::Base.new(ActionController::Base.view_paths, {}) + assert_equal "foobar", @view.render(:file => "test/scoped_array_translation") + end end -- 1.7.0