Methods
S
T
Included Modules
Instance Public methods
setup()
# File actionpack/test/controller/send_file_test.rb, line 37
def setup
  @controller = SendFileController.new
  @request = ActionController::TestRequest.new
  @response = ActionController::TestResponse.new
end
test_data()
# File actionpack/test/controller/send_file_test.rb, line 76
def test_data
  response = nil
  assert_nothing_raised { response = process('data') }
  assert_not_nil response

  assert_kind_of String, response.body
  assert_equal file_data, response.body
end
test_file_nostream()
# File actionpack/test/controller/send_file_test.rb, line 43
def test_file_nostream
  @controller.options = { :stream => false }
  response = nil
  assert_nothing_raised { response = process('file') }
  assert_not_nil response
  body = response.body
  assert_kind_of String, body
  assert_equal file_data, body
end
test_file_stream()
# File actionpack/test/controller/send_file_test.rb, line 53
def test_file_stream
  response = nil
  assert_nothing_raised { response = process('file') }
  assert_not_nil response
  assert_respond_to response.body_parts, :each
  assert_respond_to response.body_parts, :to_path

  require 'stringio'
  output = StringIO.new
  output.binmode
  output.string.force_encoding(file_data.encoding) if output.string.respond_to?(:force_encoding)
  assert_nothing_raised { response.body_parts.each { |part| output << part.to_s } }
  assert_equal file_data, output.string
end
test_file_url_based_filename()
# File actionpack/test/controller/send_file_test.rb, line 68
def test_file_url_based_filename
  @controller.options = { :url_based_filename => true }
  response = nil
  assert_nothing_raised { response = process('file') }
  assert_not_nil response
  assert_equal "attachment", response.headers["Content-Disposition"]
end
test_headers_after_send_shouldnt_include_charset()
# File actionpack/test/controller/send_file_test.rb, line 85
def test_headers_after_send_shouldnt_include_charset
  response = process('data')
  assert_equal "application/octet-stream", response.headers["Content-Type"]

  response = process('file')
  assert_equal "application/octet-stream", response.headers["Content-Type"]
end
test_send_file_headers_bang()

Test that send_file_headers! is setting the correct HTTP headers.

# File actionpack/test/controller/send_file_test.rb, line 94
def test_send_file_headers_bang
  options = {
    :type => Mime::PNG,
    :disposition => 'disposition',
    :filename => 'filename'
  }

  # Do it a few times: the resulting headers should be identical
  # no matter how many times you send with the same options.
  # Test resolving Ticket #458.
  @controller.headers = {}
  @controller.send(:send_file_headers!, options)
  @controller.send(:send_file_headers!, options)
  @controller.send(:send_file_headers!, options)

  h = @controller.headers
  assert_equal 'image/png', @controller.content_type
  assert_equal 'disposition; filename="filename"', h['Content-Disposition']
  assert_equal 'binary', h['Content-Transfer-Encoding']

  # test overriding Cache-Control: no-cache header to fix IE open/save dialog
  @controller.send(:send_file_headers!, options)
  @controller.response.prepare!
  assert_equal 'private', h['Cache-Control']
end
test_send_file_headers_guess_type_from_extension()
# File actionpack/test/controller/send_file_test.rb, line 153
def test_send_file_headers_guess_type_from_extension
  {
    'image.png' => 'image/png',
    'image.jpeg' => 'image/jpeg',
    'image.jpg' => 'image/jpeg',
    'image.tif' => 'image/tiff',
    'image.gif' => 'image/gif',
    'movie.mpg' => 'video/mpeg',
    'file.zip' => 'application/zip',
    'file.unk' => 'application/octet-stream',
    'zip' => 'application/octet-stream'
  }.each do |filename,expected_type|
    options = { :filename => filename }
    @controller.headers = {}
    @controller.send(:send_file_headers!, options)
    assert_equal expected_type, @controller.content_type
  end
end
test_send_file_headers_with_bad_symbol()
# File actionpack/test/controller/send_file_test.rb, line 144
def test_send_file_headers_with_bad_symbol
  options = {
    :type => :this_type_is_not_registered
  }

  @controller.headers = {}
  assert_raise(ArgumentError){ @controller.send(:send_file_headers!, options) }
end
test_send_file_headers_with_disposition_as_a_symbol()
# File actionpack/test/controller/send_file_test.rb, line 120
def test_send_file_headers_with_disposition_as_a_symbol
  options = {
    :type => Mime::PNG,
    :disposition => :disposition,
    :filename => 'filename'
  }

  @controller.headers = {}
  @controller.send(:send_file_headers!, options)
  assert_equal 'disposition; filename="filename"', @controller.headers['Content-Disposition']
end
test_send_file_headers_with_mime_lookup_with_symbol()
# File actionpack/test/controller/send_file_test.rb, line 132
def test_send_file_headers_with_mime_lookup_with_symbol
  options = {
    :type => :png
  }

  @controller.headers = {}
  @controller.send(:send_file_headers!, options)

  assert_equal 'image/png', @controller.content_type
end