Methods
S
T
Instance Public methods
setup()
# File actionpack/test/dispatch/response_test.rb, line 6
def setup
  @response = ActionDispatch::Response.create
  @response.request = ActionDispatch::Request.empty
end
test_can_wait_until_commit()
# File actionpack/test/dispatch/response_test.rb, line 11
def test_can_wait_until_commit
  t = Thread.new {
    @response.await_commit
  }
  @response.commit!
  assert @response.committed?
  assert t.join(0.5)
end
test_each_isnt_called_if_str_body_is_written()
# File actionpack/test/dispatch/response_test.rb, line 40
def test_each_isnt_called_if_str_body_is_written
  # Controller writes and reads response body
  each_counter = 0
  @response.body = Object.new.tap {|o| o.singleton_class.send(:define_method, :each) { |&block| each_counter += 1; block.call 'foo' } }
  @response['X-Foo'] = @response.body

  assert_equal 1, each_counter, "#each was not called once"

  # Build response
  status, headers, body = @response.to_a

  assert_equal 200, status
  assert_equal "foo", headers['X-Foo']
  assert_equal "foo", body.each.to_a.join

  # Show that #each was not called twice
  assert_equal 1, each_counter, "#each was not called once"
end
test_only_set_charset_still_defaults_to_text_html()
# File actionpack/test/dispatch/response_test.rb, line 131
def test_only_set_charset_still_defaults_to_text_html
  response = ActionDispatch::Response.new
  response.charset = "utf-16"
  _,headers,_ = response.to_a
  assert_equal "text/html; charset=utf-16", headers['Content-Type']
end
test_read_body_during_action()
# File actionpack/test/dispatch/response_test.rb, line 73
def test_read_body_during_action
  @response.body = "Hello, World!"

  # even though there's no explicitly set content-type,
  assert_equal nil, @response.content_type

  # after the action reads back @response.body,
  assert_equal "Hello, World!", @response.body

  # the response can be built.
  status, headers, body = @response.to_a
  assert_equal 200, status
  assert_equal({
    "Content-Type" => "text/html; charset=utf-8"
  }, headers)

  parts = []
  body.each { |part| parts << part }
  assert_equal ["Hello, World!"], parts
end
test_response_body_encoding()
# File actionpack/test/dispatch/response_test.rb, line 94
def test_response_body_encoding
  body = ["hello".encode(Encoding::UTF_8)]
  response = ActionDispatch::Response.new 200, {}, body
  response.request = ActionDispatch::Request.empty
  assert_equal Encoding::UTF_8, response.body.encoding
end
test_response_charset_writer()
# File actionpack/test/dispatch/response_test.rb, line 101
def test_response_charset_writer
  @response.charset = 'utf-16'
  assert_equal 'utf-16', @response.charset
  @response.charset = nil
  assert_equal 'utf-8', @response.charset
end
test_set_header_after_read_body_during_action()
# File actionpack/test/dispatch/response_test.rb, line 59
def test_set_header_after_read_body_during_action
  @response.body

  # set header after the action reads back @response.body
  @response['x-header'] = "Best of all possible worlds."

  # the response can be built.
  status, headers, body = @response.to_a
  assert_equal 200, status
  assert_equal "", body.body

  assert_equal "Best of all possible worlds.", headers['x-header']
end
test_setting_content_type_header_impacts_content_type_method()
# File actionpack/test/dispatch/response_test.rb, line 108
def test_setting_content_type_header_impacts_content_type_method
  @response.headers['Content-Type'] = "application/aaron"
  assert_equal 'application/aaron', @response.content_type
end
test_stream_close()
# File actionpack/test/dispatch/response_test.rb, line 20
def test_stream_close
  @response.stream.close
  assert @response.stream.closed?
end
test_stream_write()
# File actionpack/test/dispatch/response_test.rb, line 25
def test_stream_write
  @response.stream.write "foo"
  @response.stream.close
  assert_equal "foo", @response.body
end
test_write_after_close()
# File actionpack/test/dispatch/response_test.rb, line 31
def test_write_after_close
  @response.stream.close

  e = assert_raises(IOError) do
    @response.stream.write "omg"
  end
  assert_equal "closed stream", e.message
end