Permalink
Browse files

adds tests for #flush_output_buffer

[#4196 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
fxn authored and jeremy committed Mar 16, 2010
1 parent 986cac7 commit 9659d18c9b76f6383854af0cd3a75abb6b1784ea
Showing with 37 additions and 2 deletions.
  1. +37 −2 actionpack/test/template/capture_helper_test.rb
@@ -18,7 +18,7 @@ def test_capture_captures_the_temporary_output_buffer_in_its_block
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 @@ def test_with_output_buffer_sets_proper_encoding
@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 @@ def test_with_output_buffer_does_not_assume_there_is_an_output_buffer
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

0 comments on commit 9659d18

Please sign in to comment.