aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/output_buffer_test.rb
blob: bd49a11af1e4e2d9de4f5c2c8e7226d2b673ff7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'abstract_unit'

class OutputBufferTest < ActionController::TestCase
  class TestController < ActionController::Base
    def index
      render :text => 'foo'
    end
  end

  tests TestController

  def setup
    @vc = @controller.view_context
    get :index
    assert_equal ['foo'], body_parts
  end

  test 'output buffer is nil after rendering' do
    assert_nil output_buffer
  end

  test 'flushing ignores nil output buffer' do
    @controller.view_context.flush_output_buffer
    assert_nil output_buffer
    assert_equal ['foo'], body_parts
  end

  test 'flushing ignores empty output buffer' do
    @vc.output_buffer = ''
    @vc.flush_output_buffer
    assert_equal '', output_buffer
    assert_equal ['foo'], body_parts
  end

  test 'flushing appends the output buffer to the body parts' do
    @vc.output_buffer = 'bar'
    @vc.flush_output_buffer
    assert_equal '', output_buffer
    assert_equal ['foo', 'bar'], body_parts
  end

  if '1.9'.respond_to?(:force_encoding)
    test 'flushing preserves output buffer encoding' do
      original_buffer = ' '.force_encoding(Encoding::EUC_JP)
      @vc.output_buffer = original_buffer
      @vc.flush_output_buffer
      assert_equal ['foo', original_buffer], body_parts
      assert_not_equal original_buffer, output_buffer
      assert_equal Encoding::EUC_JP, output_buffer.encoding
    end
  end

  protected
    def output_buffer
      @vc.output_buffer
    end

    def body_parts
      @controller.response.body_parts
    end
end