scope_key_by_partial fix for Ruby 1.9 when there's virtual_path [#4202 state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
Santiago Pastorino 2010-03-16 20:12:04 -03:00 committed by Jeremy Kemper
parent 7a5da21481
commit 0c1ac36ccb
3 changed files with 10 additions and 2 deletions

View File

@ -29,9 +29,10 @@ module ActionView
private
def scope_key_by_partial(key)
if (key.respond_to?(:join) ? key.join : key.to_s).first == "."
strkey = key.respond_to?(:join) ? key.join : key.to_s
if strkey.first == "."
if @_virtual_path
@_virtual_path.gsub(%r{/_?}, ".") + key.to_s
@_virtual_path.gsub(%r{/_?}, ".") + strkey
else
raise "Cannot use t(#{key.inspect}) shortcut because path is not available"
end

View File

@ -0,0 +1 @@
<%= t(['.foo', '.bar']) %>

View File

@ -41,4 +41,10 @@ class TranslationHelperTest < ActiveSupport::TestCase
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
assert_equal "helper", @view.render(:file => "test/translation")
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