Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:jnicklas/carrierwave

  • Loading branch information...
commit 2b91dc48bf46ad2a89ef0a3a7261f0b292c20d2f 2 parents b411622 + cf4e2f1
Trevor Turk trevorturk authored
2  lib/carrierwave.rb
View
@@ -108,6 +108,4 @@ class Railtie < Rails::Railtie
end
-require 'carrierwave/orm/datamapper' if defined?(DataMapper)
-require 'carrierwave/orm/sequel' if defined?(Sequel)
require 'carrierwave/orm/mongoid' if defined?(Mongoid)
12 lib/carrierwave/uploader/store.rb
View
@@ -70,8 +70,16 @@ def store!(new_file=nil)
#
def delete_cache_id
if @cache_id
- path = File.join(cache_dir, @cache_id)
- FileUtils.rm_rf(path) if File.exists?(path) && File.directory?(path)
+ path = File.expand_path(File.join(cache_dir, @cache_id), CarrierWave.root)
+ begin
+ Dir.rmdir(path)
+ rescue Errno::ENOENT
+ # Ignore: path does not exist
+ rescue Errno::ENOTDIR
+ # Ignore: path is not a dir
+ rescue Errno::ENOTEMPTY, Errno::EEXIST
+ # Ignore: dir is not empty
+ end
end
end
4 spec/storage/fog_helper.rb
View
@@ -24,7 +24,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
@uploader.stub!(:store_path).and_return('uploads/test.jpg')
@storage = CarrierWave::Storage::Fog.new(@uploader)
- @directory = @storage.connection.directories.get(CARRIERWAVE_DIRECTORY) || @storage.connection.directories.create(:key => CARRIERWAVE_DIRECTORY)
+ @directory = @storage.connection.directories.get(CARRIERWAVE_DIRECTORY) || @storage.connection.directories.create(:key => CARRIERWAVE_DIRECTORY, :public => true)
@file = CarrierWave::SanitizedFile.new(
:tempfile => StringIO.new(File.open(file_path('test.jpg')).read),
@@ -146,7 +146,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
context "true" do
before do
directory_key = "#{CARRIERWAVE_DIRECTORY}public"
- @directory = @storage.connection.directories.create(:key => directory_key)
+ @directory = @storage.connection.directories.create(:key => directory_key, :public => true)
@uploader.stub!(:fog_directory).and_return(directory_key)
@uploader.stub!(:store_path).and_return('uploads/public.txt')
@fog_file = @storage.store!(@file)
40 spec/uploader/store_spec.rb
View
@@ -108,8 +108,16 @@
it "should delete the old cache_id" do
@uploader.cache!(@file)
- @uploader.should_receive(:delete_cache_id)
+ cache_path = @uploader.send(:cache_path) # WARNING: violating private
+ cache_id_dir = File.dirname(cache_path)
+ cache_parent_dir = File.split(cache_id_dir).first
+ File.should be_directory(cache_parent_dir)
+ File.should be_directory(cache_id_dir)
+
@uploader.store!
+
+ File.should be_directory(cache_parent_dir)
+ File.should_not be_directory(cache_id_dir)
end
context "with the delete_cache_id_after_storage option set to false" do
@@ -119,8 +127,36 @@
it "should not delete the old cache_id" do
@uploader.cache!(@file)
- @uploader.should_not_receive(:delete_cache_id)
+ cache_path = @uploader.send(:cache_path) # WARNING: violating private
+ cache_id_dir = File.dirname(cache_path)
+ cache_parent_dir = File.split(cache_id_dir).first
+ File.should be_directory(cache_parent_dir)
+ File.should be_directory(cache_id_dir)
+
+ @uploader.store!
+
+ File.should be_directory(cache_parent_dir)
+ File.should be_directory(cache_id_dir)
+ end
+ end
+
+ context "when the old cache_id directory is not empty" do
+ before do
+ @uploader.cache!(@file)
+ cache_path = @uploader.send(:cache_path) # WARNING: violating private
+ @cache_id_dir = File.dirname(cache_path)
+ @existing_file = File.join(@cache_id_dir, "exsting_file.txt")
+ File.open(@existing_file, "wb"){|f| f << "I exist"}
+ end
+
+ it "should not delete the old cache_id" do
+ @uploader.store!
+ File.should be_directory(@cache_id_dir)
+ end
+
+ it "should not delete other existing files in old cache_id dir" do
@uploader.store!
+ File.should exist @existing_file
end
end
4 spec/uploader/versions_spec.rb
View
@@ -28,7 +28,9 @@
version :micro
end
end
- @uploader_class.versions.keys.should == [:large, :thumb]
+ @uploader_class.versions.should have(2).versions
+ @uploader_class.versions.should include :large
+ @uploader_class.versions.should include :thumb
@uploader.large.versions.should be_empty
@uploader.thumb.versions.keys.should == [:mini]
@uploader.thumb.mini.versions.keys.should == [:micro]
Please sign in to comment.
Something went wrong with that request. Please try again.