aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-03-16 00:22:22 +0100
committerJeremy Kemper <jeremy@bitsweat.net>2010-03-15 16:30:31 -0700
commitc5a877f1421744096ce6ffbfce3fc1034bda880e (patch)
treed8d73b603e3392e49e955620f1a6bbde25c0ee5c /actionpack/test
parent5913dd478150710fc0b72a0568f68e13c958d6bc (diff)
downloadrails-c5a877f1421744096ce6ffbfce3fc1034bda880e.tar.gz
rails-c5a877f1421744096ce6ffbfce3fc1034bda880e.tar.bz2
rails-c5a877f1421744096ce6ffbfce3fc1034bda880e.zip
adds test coverage for with_output_buffer
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/template/capture_helper_test.rb48
1 files changed, 45 insertions, 3 deletions
diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb
index f887c9ab5b..e65f8b15ed 100644
--- a/actionpack/test/template/capture_helper_test.rb
+++ b/actionpack/test/template/capture_helper_test.rb
@@ -3,6 +3,7 @@ require 'abstract_unit'
class CaptureHelperTest < ActionView::TestCase
def setup
super
+ @av = ActionView::Base.new
@_content_for = Hash.new {|h,k| h[k] = "" }
end
@@ -13,9 +14,50 @@ class CaptureHelperTest < ActionView::TestCase
assert ! content_for?(:something_else)
end
+ def test_with_output_buffer_swaps_the_output_buffer_given_no_argument
+ assert_nil @av.output_buffer
+ buffer = @av.with_output_buffer do
+ @av.output_buffer << '.'
+ end
+ assert_equal '.', buffer
+ assert_nil @av.output_buffer
+ end
+
+ def test_with_output_buffer_swaps_the_output_buffer_with_an_argument
+ assert_nil @av.output_buffer
+ buffer = ActionView::OutputBuffer.new('.')
+ @av.with_output_buffer(buffer) do
+ @av.output_buffer << '.'
+ end
+ assert_equal '..', buffer
+ assert_nil @av.output_buffer
+ end
+
+ def test_with_output_buffer_restores_the_output_buffer
+ buffer = ActionView::OutputBuffer.new
+ @av.output_buffer = buffer
+ @av.with_output_buffer do
+ @av.output_buffer << '.'
+ end
+ assert buffer.equal?(@av.output_buffer)
+ end
+
+ unless RUBY_VERSION < '1.9'
+ 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
+ @av.output_buffer.force_encoding(alt_encoding)
+
+ @av.with_output_buffer do
+ assert alt_encoding, @av.output_buffer.encoding
+ end
+ end
+ end
+
def test_with_output_buffer_does_not_assume_there_is_an_output_buffer
- av = ActionView::Base.new
- assert_nil av.output_buffer
- assert_equal "", av.with_output_buffer {}
+ assert_nil @av.output_buffer
+ assert_equal "", @av.with_output_buffer {}
end
end