Skip to content
This repository
Browse code

adds test coverage for with_output_buffer

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit c5a877f1421744096ce6ffbfce3fc1034bda880e 1 parent 5913dd4
Xavier Noria fxn authored jeremy committed

Showing 1 changed file with 45 additions and 3 deletions. Show diff stats Hide diff stats

  1. +45 3 actionpack/test/template/capture_helper_test.rb
48 actionpack/test/template/capture_helper_test.rb
@@ -3,6 +3,7 @@
3 3 class CaptureHelperTest < ActionView::TestCase
4 4 def setup
5 5 super
  6 + @av = ActionView::Base.new
6 7 @_content_for = Hash.new {|h,k| h[k] = "" }
7 8 end
8 9
@@ -13,9 +14,50 @@ def test_content_for
13 14 assert ! content_for?(:something_else)
14 15 end
15 16
  17 + def test_with_output_buffer_swaps_the_output_buffer_given_no_argument
  18 + assert_nil @av.output_buffer
  19 + buffer = @av.with_output_buffer do
  20 + @av.output_buffer << '.'
  21 + end
  22 + assert_equal '.', buffer
  23 + assert_nil @av.output_buffer
  24 + end
  25 +
  26 + def test_with_output_buffer_swaps_the_output_buffer_with_an_argument
  27 + assert_nil @av.output_buffer
  28 + buffer = ActionView::OutputBuffer.new('.')
  29 + @av.with_output_buffer(buffer) do
  30 + @av.output_buffer << '.'
  31 + end
  32 + assert_equal '..', buffer
  33 + assert_nil @av.output_buffer
  34 + end
  35 +
  36 + def test_with_output_buffer_restores_the_output_buffer
  37 + buffer = ActionView::OutputBuffer.new
  38 + @av.output_buffer = buffer
  39 + @av.with_output_buffer do
  40 + @av.output_buffer << '.'
  41 + end
  42 + assert buffer.equal?(@av.output_buffer)
  43 + end
  44 +
  45 + unless RUBY_VERSION < '1.9'
  46 + def test_with_output_buffer_sets_proper_encoding
  47 + @av.output_buffer = ActionView::OutputBuffer.new
  48 +
  49 + # Ensure we set the output buffer to an encoding different than the default one.
  50 + alt_encoding = @av.output_buffer.encoding == Encoding::US_ASCII ? Encoding::UTF_8 : Encoding::US_ASCII
  51 + @av.output_buffer.force_encoding(alt_encoding)
  52 +
  53 + @av.with_output_buffer do
  54 + assert alt_encoding, @av.output_buffer.encoding
  55 + end
  56 + end
  57 + end
  58 +
16 59 def test_with_output_buffer_does_not_assume_there_is_an_output_buffer
17   - av = ActionView::Base.new
18   - assert_nil av.output_buffer
19   - assert_equal "", av.with_output_buffer {}
  60 + assert_nil @av.output_buffer
  61 + assert_equal "", @av.with_output_buffer {}
20 62 end
21 63 end

0 comments on commit c5a877f

Please sign in to comment.
Something went wrong with that request. Please try again.