Permalink
Browse files

Merge pull request #30361 from mfo/master

StreamingTemplateRenderer fails to forward I18n.locale in layouts
  • Loading branch information...
eileencodes committed Dec 11, 2017
2 parents a41fa1f + 6d3b57f commit 4edce566ad13d54c86637caf56750df0d6dc7b1a
@@ -65,7 +65,9 @@ def delayed_render(buffer, template, layout, view, locals)
yielder = lambda { |*name| view._layout_for(*name) }
instrument(:template, identifier: template.identifier, layout: layout.try(:virtual_path)) do
outer_config = I18n.config
fiber = Fiber.new do
I18n.config = outer_config
if layout
layout.render(view, locals, output, &yielder)
else
@@ -0,0 +1,2 @@
layout.locale: <%= I18n.locale %>
<%= yield %>
@@ -0,0 +1 @@
view.locale: <%= I18n.locale %>
@@ -5,7 +5,7 @@
class TestController < ActionController::Base
end
class FiberedTest < ActiveSupport::TestCase
class SetupFiberedBase < ActiveSupport::TestCase
def setup
view_paths = ActionController::Base.view_paths
@assigns = { secret: "in the sauce", name: nil }
@@ -25,7 +25,9 @@ def buffered_render(options)
end
string
end
end
class FiberedTest < SetupFiberedBase
def test_streaming_works
content = []
body = render_body(template: "test/hello_world", layout: "layouts/yield")
@@ -111,3 +113,20 @@ def test_render_with_streaming_and_capture
buffered_render(template: "test/streaming", layout: "layouts/streaming_with_capture")
end
end
class FiberedWithLocaleTest < SetupFiberedBase
def setup
@old_locale = I18n.locale
I18n.locale = "da"
super
end
def teardown
I18n.locale = @old_locale
end
def test_render_with_streaming_and_locale
assert_equal "layout.locale: da\nview.locale: da\n\n",
buffered_render(template: "test/streaming_with_locale", layout: "layouts/streaming_with_locale")
end
end

0 comments on commit 4edce56

Please sign in to comment.