spec/ftp_spec.rb in carrierwave-ftp-0.3.1 vs spec/ftp_spec.rb in carrierwave-ftp-0.4.0
- old
+ new
@@ -5,18 +5,19 @@
storage :ftp
end
describe CarrierWave::Storage::FTP do
before do
- CarrierWave.configure do |config|
+ FtpUploader.configure do |config|
config.reset_config
config.ftp_host = 'ftp.testcarrierwave.dev'
config.ftp_user = 'test_user'
config.ftp_passwd = 'test_passwd'
config.ftp_folder = '~/public_html'
config.ftp_url = 'http://testcarrierwave.dev'
config.ftp_passive = true
+ config.ftp_chmod = true
end
@file = CarrierWave::SanitizedFile.new(file_path('test.jpg'))
FtpUploader.stub(:store_path).and_return('uploads/test.jpg')
@storage = CarrierWave::Storage::FTP.new(FtpUploader)
@@ -36,24 +37,54 @@
ftp.should_receive(:login).with('test_user', 'test_passwd')
ftp.should_receive(:passive=).with(true)
ftp.should_receive(:mkdir_p).with('~/public_html/uploads')
ftp.should_receive(:chdir).with('~/public_html/uploads')
ftp.should_receive(:put).with(@file.path, 'test.jpg')
+ ftp.should_receive(:sendcmd).with("SITE CHMOD 644 ~/public_html/uploads/test.jpg")
ftp.should_receive(:quit)
@stored = @storage.store!(@file)
end
+ describe 'when CHMOD is disabled' do
+ before do
+ FtpUploader.configure do |config|
+ config.ftp_chmod = false
+ end
+ end
+
+ it "opens/closes an ftp connection to the given host" do
+ ftp = double(:ftp_connection)
+ ftp_params = [
+ 'ftp.testcarrierwave.dev',
+ 'test_user',
+ 'test_passwd',
+ 21
+ ]
+
+ Net::FTP.should_receive(:new).and_return(ftp)
+ ftp.should_receive(:connect).with('ftp.testcarrierwave.dev', 21)
+ ftp.should_receive(:login).with('test_user', 'test_passwd')
+ ftp.should_receive(:passive=).with(true)
+ ftp.should_receive(:mkdir_p).with('~/public_html/uploads')
+ ftp.should_receive(:chdir).with('~/public_html/uploads')
+ ftp.should_receive(:put).with(@file.path, 'test.jpg')
+ ftp.should_receive(:quit)
+ @stored = @storage.store!(@file)
+ end
+ end
+
describe 'after upload' do
before do
ftp = double(:ftp_connection)
Net::FTP.stub(:new).and_return(ftp)
ftp.stub(:connect)
ftp.stub(:login)
ftp.stub(:passive=)
ftp.stub(:mkdir_p)
ftp.stub(:chdir)
ftp.stub(:put)
+ ftp.stub(:sendcmd)
ftp.stub(:quit)
@stored = @storage.store!(@file)
end
it "returns a url based on directory" do
@@ -73,9 +104,10 @@
@ftp.stub(:login)
@ftp.stub(:passive=)
@ftp.stub(:mkdir_p)
@ftp.stub(:chdir)
@ftp.stub(:put)
+ @ftp.stub(:sendcmd)
@ftp.stub(:quit)
@stored = @storage.store!(@file)
end
it "deletes a file" do