Commit c695055b by Nate Holland Committed by Sid Raval

Rewind file in Storage::Fog if bucket does not exist

There was a bug in the code where if you created a bucket the file would
get read but not rewind on the first pass through (when the bucket
didn't exist). So when we went into the retry logic the file would
already be read and zero bytes would get copied over from the file. This
fixes that by rewinding the file during the retry so it gets correctly
copied over the second time around.
parent 82b3114b
...@@ -117,6 +117,7 @@ module Paperclip ...@@ -117,6 +117,7 @@ module Paperclip
raise if retried raise if retried
retried = true retried = true
directory.save directory.save
file.rewind
retry retry
ensure ensure
file.rewind file.rewind
......
...@@ -206,6 +206,11 @@ describe Paperclip::Storage::Fog do ...@@ -206,6 +206,11 @@ describe Paperclip::Storage::Fog do
assert @dummy.save assert @dummy.save
assert @connection.directories.get(@fog_directory) assert @connection.directories.get(@fog_directory)
end end
it "sucessfully rewinds the file during bucket creation" do
assert @dummy.save
expect(Paperclip.io_adapters.for(@dummy.avatar).read.length).to be > 0
end
end end
context "with a bucket" do context "with a bucket" do
......
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