Commit 9324ba89 by Jon Yurek

Remove empty directories when possible.

parent b8506d36
......@@ -56,6 +56,14 @@ module Paperclip
rescue Errno::ENOENT => e
# ignore file-not-found, let everything else pass
end
begin
while(true)
path = File.dirname(path)
FileUtils.rmdir(path)
end
rescue Errno::ENOTEMPTY, Errno::ENOENT, Errno::EINVAL
# Stop trying to remove parent directories
end
end
@queued_for_delete = []
end
......
......@@ -49,6 +49,46 @@ class IntegrationTest < Test::Unit::TestCase
end
end
context "A model with attachments scoped under an id" do
setup do
rebuild_model :styles => { :large => "100x100",
:medium => "50x50" },
:path => ":rails_root/tmp/:id/:attachments/:style.:extension"
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"), 'rb')
@dummy.avatar = @file
end
context "when saved" do
setup do
@dummy.save
@saved_path = @dummy.avatar.path(:large)
end
should "have a large file in the right place" do
assert File.exists?(@dummy.avatar.path(:large))
end
context "and deleted" do
setup do
@dummy.avatar = nil
@dummy.save
end
should "not have a large file in the right place anymore" do
assert ! File.exists?(@saved_path)
end
should "not have its next two parent directories" do
assert ! File.exists?(File.dirname(@saved_path))
assert ! File.exists?(File.dirname(File.dirname(@saved_path)))
end
end
end
end
context "A model with no attachment validation" do
setup do
rebuild_model :styles => { :large => "300x300>",
......
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