Commit d46a1afe by Prem Sichanugrist

Rewind tempfiles after get saved to storages

Re-fix of #838, #766, #911
parent cdf85a20
...@@ -90,6 +90,8 @@ module Paperclip ...@@ -90,6 +90,8 @@ module Paperclip
retried = true retried = true
directory.save directory.save
retry retry
ensure
file.rewind
end end
end end
......
...@@ -310,6 +310,8 @@ module Paperclip ...@@ -310,6 +310,8 @@ module Paperclip
rescue AWS::S3::Errors::NoSuchBucket => e rescue AWS::S3::Errors::NoSuchBucket => e
create_bucket create_bucket
retry retry
ensure
file.rewind
end end
end end
......
...@@ -111,6 +111,12 @@ class FogTest < Test::Unit::TestCase ...@@ -111,6 +111,12 @@ class FogTest < Test::Unit::TestCase
directory.destroy directory.destroy
end end
should "be rewinded after flush_writes" do
files = @dummy.avatar.queued_for_write.map{ |style, file| file }
@dummy.save
assert files.none?(&:eof?), "Expect all the files to be rewinded."
end
should "pass the content type to the Fog::Storage::AWS::Files instance" do should "pass the content type to the Fog::Storage::AWS::Files instance" do
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash| Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
hash[:content_type] hash[:content_type]
......
...@@ -569,6 +569,12 @@ class S3Test < Test::Unit::TestCase ...@@ -569,6 +569,12 @@ class S3Test < Test::Unit::TestCase
assert_match %r{^http://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url assert_match %r{^http://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url
end end
should "be rewinded after flush_writes" do
files = @dummy.avatar.queued_for_write.map{ |style, file| file.tap(&:read) }
@dummy.save
assert files.none?(&:eof?), "Expect all the files to be rewinded."
end
context "and saved" do context "and saved" do
setup do setup do
object = stub object = stub
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment