diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2015-03-01 16:20:27 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2015-03-01 16:20:27 +0900 |
commit | 35d12ef3f15184c45b51bfab9b399fe73a7a3ce3 (patch) | |
tree | db1e62352dd05bcb56f36a61699e7f06d14aa2bf /actionview | |
parent | 22e0a22d5f98e162290d9820891d8191e720ad3b (diff) | |
download | rails-35d12ef3f15184c45b51bfab9b399fe73a7a3ce3.tar.gz rails-35d12ef3f15184c45b51bfab9b399fe73a7a3ce3.tar.bz2 rails-35d12ef3f15184c45b51bfab9b399fe73a7a3ce3.zip |
fix ActionView::Template::Error when using Streaming with capture.
can't acquire a encoding from StreamingBuffer. fixes #12001
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/helpers/capture_helper.rb | 4 | ||||
-rw-r--r-- | actionview/test/fixtures/layouts/streaming_with_capture.erb | 6 | ||||
-rw-r--r-- | actionview/test/template/streaming_render_test.rb | 4 |
3 files changed, 13 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/capture_helper.rb b/actionview/lib/action_view/helpers/capture_helper.rb index 5a3223968f..a67ba580f1 100644 --- a/actionview/lib/action_view/helpers/capture_helper.rb +++ b/actionview/lib/action_view/helpers/capture_helper.rb @@ -195,7 +195,9 @@ module ActionView def with_output_buffer(buf = nil) #:nodoc: unless buf buf = ActionView::OutputBuffer.new - buf.force_encoding(output_buffer.encoding) if output_buffer + if output_buffer && output_buffer.respond_to?(:encoding) + buf.force_encoding(output_buffer.encoding) + end end self.output_buffer, old_buffer = buf, output_buffer yield diff --git a/actionview/test/fixtures/layouts/streaming_with_capture.erb b/actionview/test/fixtures/layouts/streaming_with_capture.erb new file mode 100644 index 0000000000..538c19ce3a --- /dev/null +++ b/actionview/test/fixtures/layouts/streaming_with_capture.erb @@ -0,0 +1,6 @@ +<%= yield :header -%> +<%= capture do %> + this works +<% end %> +<%= yield :footer -%> +<%= yield(:unknown).presence || "." -%> diff --git a/actionview/test/template/streaming_render_test.rb b/actionview/test/template/streaming_render_test.rb index ec537775be..d06ba4ceb0 100644 --- a/actionview/test/template/streaming_render_test.rb +++ b/actionview/test/template/streaming_render_test.rb @@ -104,4 +104,8 @@ class FiberedTest < ActiveSupport::TestCase buffered_render(:template => "test/nested_streaming", :layout => "layouts/streaming") end + def test_render_with_streaming_and_capture + assert_equal "Yes, \n this works\n like a charm.", + buffered_render(template: "test/streaming", layout: "layouts/streaming_with_capture") + end end |