Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Rewind tempfiles after get saved to storages
Browse files Browse the repository at this point in the history
Re-fix of #838, #766, #911
  • Loading branch information
sikachu committed Jun 15, 2012
1 parent cdf85a2 commit d46a1af
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/paperclip/storage/fog.rb
Expand Up @@ -90,6 +90,8 @@ def flush_writes
retried = true retried = true
directory.save directory.save
retry retry
ensure
file.rewind
end end
end end


Expand Down
2 changes: 2 additions & 0 deletions lib/paperclip/storage/s3.rb
Expand Up @@ -310,6 +310,8 @@ def flush_writes #:nodoc:
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


Expand Down
6 changes: 6 additions & 0 deletions test/storage/fog_test.rb
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions test/storage/s3_test.rb
Expand Up @@ -569,6 +569,12 @@ def counter
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
Expand Down

0 comments on commit d46a1af

Please sign in to comment.