From c87206cc575031ae5d422a7729e32954e1184b26 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 14 Sep 2007 07:34:45 +0000 Subject: Add option to force binary mode on tempfile used for fixture_file_upload. Closes #6380. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7478 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/test_test.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index 10818fe1c9..8a57f37b68 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -460,6 +460,30 @@ XML assert_equal file.path, file.local_path assert_equal File.read(path), file.read end + + def test_test_uploaded_file_with_binary + filename = 'mona_lisa.jpg' + path = "#{FILES_DIR}/#{filename}" + content_type = 'image/png' + + binary_uploaded_file = ActionController::TestUploadedFile.new(path, content_type, :binary) + assert_equal File.open(path, 'rb').read, binary_uploaded_file.read + + plain_uploaded_file = ActionController::TestUploadedFile.new(path, content_type) + assert_equal File.open(path, 'r').read, plain_uploaded_file.read + end + + def test_fixture_file_upload_with_binary + filename = 'mona_lisa.jpg' + path = "#{FILES_DIR}/#{filename}" + content_type = 'image/jpg' + + binary_file_upload = fixture_file_upload(path, content_type, :binary) + assert_equal File.open(path, 'rb').read, binary_file_upload.read + + plain_file_upload = fixture_file_upload(path, content_type) + assert_equal File.open(path, 'r').read, plain_file_upload.read + end def test_fixture_file_upload post :test_file_upload, :file => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") -- cgit v1.2.3