aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/capture_helper_test.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-03-16 21:05:01 +0100
committerJeremy Kemper <jeremy@bitsweat.net>2010-03-16 13:16:44 -0700
commit9659d18c9b76f6383854af0cd3a75abb6b1784ea (patch)
tree50c8dea07ab3e8f8ab344016f03fad0c2ea2a7fe /actionpack/test/template/capture_helper_test.rb
parent986cac73e3c56b3dfa22fd1464f6913e38d32cc3 (diff)
downloadrails-9659d18c9b76f6383854af0cd3a75abb6b1784ea.tar.gz
rails-9659d18c9b76f6383854af0cd3a75abb6b1784ea.tar.bz2
rails-9659d18c9b76f6383854af0cd3a75abb6b1784ea.zip
adds tests for #flush_output_buffer
[#4196 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'actionpack/test/template/capture_helper_test.rb')
-rw-r--r--actionpack/test/template/capture_helper_test.rb39
1 files changed, 37 insertions, 2 deletions
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