aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/test_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/controller/test_test.rb')
-rw-r--r--actionpack/test/controller/test_test.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index ba6c7f4299..38898a1f75 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -511,16 +511,26 @@ XML
FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart'
+ if RUBY_VERSION < '1.9'
+ READ_BINARY = 'rb'
+ READ_PLAIN = 'r'
+ else
+ READ_BINARY = 'rb:binary'
+ READ_PLAIN = 'r:binary'
+ end
+
def test_test_uploaded_file
filename = 'mona_lisa.jpg'
path = "#{FILES_DIR}/#{filename}"
content_type = 'image/png'
+ expected = File.read(path)
+ expected.force_encoding(Encoding::BINARY) if expected.respond_to?(:force_encoding)
file = ActionController::TestUploadedFile.new(path, content_type)
assert_equal filename, file.original_filename
assert_equal content_type, file.content_type
assert_equal file.path, file.local_path
- assert_equal File.read(path), file.read
+ assert_equal expected, file.read
end
def test_test_uploaded_file_with_binary
@@ -529,10 +539,10 @@ XML
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
+ assert_equal File.open(path, READ_BINARY).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
+ assert_equal File.open(path, READ_PLAIN).read, plain_uploaded_file.read
end
def test_fixture_file_upload_with_binary
@@ -541,10 +551,10 @@ XML
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
+ assert_equal File.open(path, READ_BINARY).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
+ assert_equal File.open(path, READ_PLAIN).read, plain_file_upload.read
end
def test_fixture_file_upload