spec/integration_spec.rb in paperclip-storage-ftp-1.2.1 vs spec/integration_spec.rb in paperclip-storage-ftp-1.2.2
- old
+ new
@@ -1,7 +1,8 @@
require "spec_helper"
require "timeout"
+require "fileutils"
describe "paperclip-storage-ftp", :integration => true do
before(:all) do
require "support/integration/ftp_server"
@@ -21,20 +22,22 @@
let(:uploaded_file_server1_thumb) { FtpServer::USER1_PATH + "/thumb/avatar.jpg" }
let(:uploaded_file_server2) { FtpServer::USER2_PATH + "/original/avatar.jpg" }
let(:uploaded_file_server2_medium) { FtpServer::USER2_PATH + "/medium/avatar.jpg" }
let(:uploaded_file_server2_thumb) { FtpServer::USER2_PATH + "/thumb/avatar.jpg" }
+ let(:uploaded_file_server1_other) { FtpServer::USER1_PATH + "/original/foo.txt" }
+
it "stores the attachment on the ftp servers" do
user.avatar = file
user.save!
- File.exists?(uploaded_file_server1).should be_true
- File.exists?(uploaded_file_server1_medium).should be_true
- File.exists?(uploaded_file_server1_thumb).should be_true
- File.exists?(uploaded_file_server2).should be_true
- File.exists?(uploaded_file_server2_medium).should be_true
- File.exists?(uploaded_file_server2_thumb).should be_true
+ File.exists?(uploaded_file_server1).should be true
+ File.exists?(uploaded_file_server1_medium).should be true
+ File.exists?(uploaded_file_server1_thumb).should be true
+ File.exists?(uploaded_file_server2).should be true
+ File.exists?(uploaded_file_server2_medium).should be true
+ File.exists?(uploaded_file_server2_thumb).should be true
file.size.should == File.size(uploaded_file_server1)
file.size.should == File.size(uploaded_file_server2)
end
@@ -42,18 +45,40 @@
user.avatar = file
user.save!
user.destroy
- File.exists?(uploaded_file_server1).should be_false
- File.exists?(uploaded_file_server1_medium).should be_false
- File.exists?(uploaded_file_server1_thumb).should be_false
- File.exists?(uploaded_file_server2).should be_false
- File.exists?(uploaded_file_server2_medium).should be_false
- File.exists?(uploaded_file_server2_thumb).should be_false
+ File.exists?(uploaded_file_server1).should be false
+ File.exists?(uploaded_file_server1_medium).should be false
+ File.exists?(uploaded_file_server1_thumb).should be false
+
+ File.exists?(uploaded_file_server2).should be false
+ File.exists?(uploaded_file_server2_medium).should be false
+ File.exists?(uploaded_file_server2_thumb).should be false
end
+ it "removes empty parent directories after image deletion" do
+ user.avatar = file
+ user.save!
+
+ user.destroy
+
+ Dir.exists?(File.dirname(uploaded_file_server1)).should be false
+ Dir.exists?(File.dirname(uploaded_file_server2)).should be false
+ end
+
+ it "does not remove parent directories which are not empty" do
+ user.avatar = file
+ user.save!
+
+ FileUtils.touch(uploaded_file_server1_other)
+
+ user.destroy
+
+ File.exists?(uploaded_file_server1_other).should be true
+ end
+
it "survives temporarily closed ftp connections" do
user.avatar = file
user.save!
user.avatar = nil
@@ -62,24 +87,24 @@
FtpServer.restart
user.avatar = file
user.save!
- File.exists?(uploaded_file_server1).should be_true
- File.exists?(uploaded_file_server2).should be_true
+ File.exists?(uploaded_file_server1).should be true
+ File.exists?(uploaded_file_server2).should be true
end
it "allows ignoring failed connections" do
user = UserIgnoringFailingConnection.new
user.avatar = file
expect{ user.save! }.to_not raise_error
- File.exists?(uploaded_file_server1).should be_true
- File.exists?(uploaded_file_server1_medium).should be_true
- File.exists?(uploaded_file_server1_thumb).should be_true
- File.exists?(uploaded_file_server2).should be_false
- File.exists?(uploaded_file_server2_medium).should be_false
- File.exists?(uploaded_file_server2_thumb).should be_false
+ File.exists?(uploaded_file_server1).should be true
+ File.exists?(uploaded_file_server1_medium).should be true
+ File.exists?(uploaded_file_server1_thumb).should be true
+ File.exists?(uploaded_file_server2).should be false
+ File.exists?(uploaded_file_server2_medium).should be false
+ File.exists?(uploaded_file_server2_thumb).should be false
end
it "raises a SystemCallError when not ignoring failed connections" do
user = UserNotIgnoringFailingConnection.new
user.avatar = file