Skip to content

Commit

Permalink
Merge pull request thoughtbot#811 from brumm/master
Browse files Browse the repository at this point in the history
Fixes AWS::S3::Errors::RequestTimeout on Model#save
  • Loading branch information
sikachu committed Apr 5, 2012
2 parents 05cda02 + 74c88f1 commit 818281d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/paperclip/io_adapters/attachment_adapter.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/paperclip/io_adapters/file_adapter.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/paperclip/io_adapters/uploaded_file_adapter.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/attachment_adapter_test.rb
Expand Up @@ -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)
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/file_adapter_test.rb
Expand Up @@ -4,13 +4,18 @@ 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

should "get the right filename" do
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
Expand Down
17 changes: 15 additions & 2 deletions test/uploaded_file_adapter_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 818281d

Please sign in to comment.