diff --git a/lib/paperclip/io_adapters/attachment_adapter.rb b/lib/paperclip/io_adapters/attachment_adapter.rb index 69ee55c3c..7719af474 100644 --- a/lib/paperclip/io_adapters/attachment_adapter.rb +++ b/lib/paperclip/io_adapters/attachment_adapter.rb @@ -49,6 +49,7 @@ def cache_current_values def copy_to_tempfile(src) dest = Tempfile.new(src.original_filename) + dest.binmode FileUtils.cp(src.path(:original), dest.path) dest end diff --git a/lib/paperclip/io_adapters/file_adapter.rb b/lib/paperclip/io_adapters/file_adapter.rb index a4c523c6a..515b6ff86 100644 --- a/lib/paperclip/io_adapters/file_adapter.rb +++ b/lib/paperclip/io_adapters/file_adapter.rb @@ -57,6 +57,7 @@ def path def copy_to_tempfile(src) dest = Tempfile.new(original_filename) + dest.binmode FileUtils.cp(src.path, dest.path) dest end diff --git a/lib/paperclip/io_adapters/uploaded_file_adapter.rb b/lib/paperclip/io_adapters/uploaded_file_adapter.rb index ef0828f5f..36f8777cc 100644 --- a/lib/paperclip/io_adapters/uploaded_file_adapter.rb +++ b/lib/paperclip/io_adapters/uploaded_file_adapter.rb @@ -51,6 +51,7 @@ def path def copy_to_tempfile(src) dest = Tempfile.new(original_filename) + dest.binmode FileUtils.cp(src.path, dest.path) dest end diff --git a/test/attachment_adapter_test.rb b/test/attachment_adapter_test.rb index 87e44cb6d..d4cda57be 100644 --- a/test/attachment_adapter_test.rb +++ b/test/attachment_adapter_test.rb @@ -5,6 +5,8 @@ def setup rebuild_model :path => "tmp/:class/:attachment/:style/:filename" @attachment = Dummy.new.avatar @file = File.new(fixture_file("5k.png")) + @file.binmode + @attachment.assign(@file) @attachment.save @subject = Paperclip.io_adapters.for(@attachment) @@ -14,6 +16,10 @@ def setup assert_equal "5k.png", @subject.original_filename end + should "force binmode on tempfile" do + assert @subject.instance_variable_get("@tempfile").binmode? + end + should "get the content type" do assert_equal "image/png", @subject.content_type end diff --git a/test/file_adapter_test.rb b/test/file_adapter_test.rb index f9e1ee22b..61c9a455e 100644 --- a/test/file_adapter_test.rb +++ b/test/file_adapter_test.rb @@ -4,6 +4,7 @@ class FileAdapterTest < Test::Unit::TestCase context "a new instance" do setup do @file = File.new(fixture_file("5k.png")) + @file.binmode @subject = Paperclip.io_adapters.for(@file) end @@ -11,6 +12,10 @@ class FileAdapterTest < Test::Unit::TestCase assert_equal "5k.png", @subject.original_filename end + should "force binmode on tempfile" do + assert @subject.instance_variable_get("@tempfile").binmode? + end + should "get the content type" do assert_equal "image/png", @subject.content_type end diff --git a/test/uploaded_file_adapter_test.rb b/test/uploaded_file_adapter_test.rb index c27c7846e..0d120f433 100644 --- a/test/uploaded_file_adapter_test.rb +++ b/test/uploaded_file_adapter_test.rb @@ -5,11 +5,14 @@ class UploadedFileAdapterTest < Test::Unit::TestCase context "with UploadedFile responding to #tempfile" do setup do class UploadedFile < OpenStruct; end + tempfile = File.new(fixture_file("5k.png")) + tempfile.binmode + @file = UploadedFile.new( :original_filename => "5k.png", :content_type => "image/png", :head => "", - :tempfile => File.new(fixture_file("5k.png")) + :tempfile => tempfile ) @subject = Paperclip.io_adapters.for(@file) end @@ -18,6 +21,10 @@ class UploadedFile < OpenStruct; end assert_equal "5k.png", @subject.original_filename end + should "force binmode on tempfile" do + assert @subject.instance_variable_get("@tempfile").binmode? + end + should "get the content type" do assert_equal "image/png", @subject.content_type end @@ -58,6 +65,10 @@ class UploadedFile < OpenStruct; end assert_equal "5k.png", @subject.original_filename end + should "force binmode on tempfile" do + assert @subject.instance_variable_get("@tempfile").binmode? + end + should "get the content type" do assert_equal "image/png", @subject.content_type end @@ -76,7 +87,9 @@ class UploadedFile < OpenStruct; end end should "read the contents of the file" do - expected = File.new(@file.path).read + expected_file = File.new(@file.path) + expected_file.binmode + expected = expected_file.read assert expected.length > 0 assert_equal expected, @subject.read end