aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template
diff options
context:
space:
mode:
authormfo <fourcade.m@gmail.com>2017-11-25 19:37:33 +0100
committermfo <fourcade.m@gmail.com>2017-11-25 21:32:02 +0100
commit6d3b57fe423e18d61ae457a718c0f9901a173ace (patch)
treef4f9b0c1de239747691d6dd37e5bdc6f755353c9 /actionview/test/template
parent72dec81206a4dfc0f14300fa9d40aea240d5b1da (diff)
downloadrails-6d3b57fe423e18d61ae457a718c0f9901a173ace.tar.gz
rails-6d3b57fe423e18d61ae457a718c0f9901a173ace.tar.bz2
rails-6d3b57fe423e18d61ae457a718c0f9901a173ace.zip
fix(streaming_template_renderer): I18n.locale broken in layout. I18n gem stores the current locale in Thread.current[:local] (see: https://github.com/svenfuchs/i18n/blob/master/lib/i18n.rb#L23). StreamingTemplateRenderer is implemented with Fiber which have its own stack of locals and can not access Thread.current.locals(keys, see: https://ruby-doc.org/core-2.2.0/Thread.html#class-Thread-label-Fiber-local+vs.+Thread-local).
Diffstat (limited to 'actionview/test/template')
-rw-r--r--actionview/test/template/streaming_render_test.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/actionview/test/template/streaming_render_test.rb b/actionview/test/template/streaming_render_test.rb
index 23edf7b538..ef000300cc 100644
--- a/actionview/test/template/streaming_render_test.rb
+++ b/actionview/test/template/streaming_render_test.rb
@@ -5,7 +5,7 @@ require "abstract_unit"
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 @@ class FiberedTest < ActiveSupport::TestCase
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 @@ class FiberedTest < ActiveSupport::TestCase
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