Commit 7696b88d by Daniel Evans

Adding tests and logic to ensure that tempfiles are closed and unlinked after…

Adding tests and logic to ensure that tempfiles are closed and unlinked after queued_for_writes finishes uploading/saving
parent 74784558
......@@ -420,5 +420,13 @@ module Paperclip
end
end
# called by storage after the writes are flushed and before @queued_for_writes is cleared
def after_flush_writes
@queued_for_write.each do |style, file|
file.close unless file.closed?
file.unlink if file.respond_to?(:unlink) && File.exist?(file.path)
end
end
end
end
......@@ -46,6 +46,9 @@ module Paperclip
end
FileUtils.chmod(0666&~File.umask, path(style_name))
end
after_flush_writes # allows attachment to clean up temp files
@queued_for_write = {}
end
......
......@@ -82,6 +82,9 @@ module Paperclip
retry
end
end
after_flush_writes # allows attachment to clean up temp files
@queued_for_write = {}
end
......
......@@ -196,6 +196,9 @@ module Paperclip
raise
end
end
after_flush_writes # allows attachment to clean up temp files
@queued_for_write = {}
end
......
......@@ -24,6 +24,14 @@ class FogTest < Test::Unit::TestCase
assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../public/avatars/5k.png")),
@dummy.avatar.path
end
should "clean up file objects" do
File.stubs(:exist?).returns(true)
Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()
@dummy.save!
end
end
setup do
......
......@@ -29,6 +29,14 @@ class StorageTest < Test::Unit::TestCase
@dummy.save
assert File.exists?(@dummy.avatar.path(:thumbnail))
end
should "clean up file objects" do
File.stubs(:exist?).returns(true)
Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()
@dummy.save!
end
end
context "Parsing S3 credentials" do
......@@ -349,6 +357,15 @@ class StorageTest < Test::Unit::TestCase
end
end
should "delete tempfiles" do
AWS::S3::S3Object.stubs(:store).with(@dummy.avatar.path, anything, 'testing', :content_type => 'image/png', :access => :public_read)
File.stubs(:exist?).returns(true)
Paperclip::Tempfile.any_instance.expects(:close).at_least_once()
Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once()
@dummy.save!
end
context "and saved without a bucket" do
setup do
class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
......
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