From 9659d18c9b76f6383854af0cd3a75abb6b1784ea Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 16 Mar 2010 21:05:01 +0100 Subject: adds tests for #flush_output_buffer [#4196 state:committed] Signed-off-by: Jeremy Kemper --- actionpack/test/template/capture_helper_test.rb | 39 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'actionpack/test/template/capture_helper_test.rb') diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb index c1e83fc04d..2216e6b578 100644 --- a/actionpack/test/template/capture_helper_test.rb +++ b/actionpack/test/template/capture_helper_test.rb @@ -18,7 +18,7 @@ class CaptureHelperTest < ActionView::TestCase assert_kind_of ActionView::NonConcattingString, string end - def test_capture_captures_the_value_returned_by_the_block_in_the_temporary_buffer_is_blank + def test_capture_captures_the_value_returned_by_the_block_if_the_temporary_buffer_is_blank string = @av.capture('foo', 'bar') do |a, b| a + b end @@ -70,7 +70,7 @@ class CaptureHelperTest < ActionView::TestCase @av.output_buffer = ActionView::OutputBuffer.new # Ensure we set the output buffer to an encoding different than the default one. - alt_encoding = @av.output_buffer.encoding == Encoding::US_ASCII ? Encoding::UTF_8 : Encoding::US_ASCII + alt_encoding = alt_encoding(@av.output_buffer) @av.output_buffer.force_encoding(alt_encoding) @av.with_output_buffer do @@ -83,4 +83,39 @@ class CaptureHelperTest < ActionView::TestCase assert_nil @av.output_buffer assert_equal "", @av.with_output_buffer {} end + + def test_flush_output_buffer_concats_output_buffer_to_response + view = view_with_controller + assert_equal [], view.response.body_parts + + view.output_buffer << 'OMG' + view.flush_output_buffer + assert_equal ['OMG'], view.response.body_parts + assert_equal '', view.output_buffer + + view.output_buffer << 'foobar' + view.flush_output_buffer + assert_equal ['OMG', 'foobar'], view.response.body_parts + assert_equal '', view.output_buffer + end + + unless RUBY_VERSION < '1.9' + def test_flush_output_buffer_preserves_the_encoding_of_the_output_buffer + view = view_with_controller + alt_encoding = alt_encoding(view.output_buffer) + view.output_buffer.force_encoding(alt_encoding) + flush_output_buffer + assert_equal alt_encoding, view.output_buffer.encoding + end + end + + def alt_encoding(output_buffer) + output_buffer.encoding == Encoding::US_ASCII ? Encoding::UTF_8 : Encoding::US_ASCII + end + + def view_with_controller + returning(ActionView::Base.for_controller(TestController.new)) do |view| + view.output_buffer = ActionView::OutputBuffer.new + end + end end -- cgit v1.2.3