Skip to content

Commit

Permalink
Combine delete_tmp_file_after_storage and delete_cache_id_after_stora…
Browse files Browse the repository at this point in the history
…ge options, closes carrierwaveuploader#398

delete_tmp_file_after_storage is now the only configuration option and it defaults to true
  • Loading branch information
bensie committed Jul 20, 2011
1 parent d29e3a5 commit 6943676
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
2 changes: 0 additions & 2 deletions lib/carrierwave/uploader/configuration.rb
Expand Up @@ -37,7 +37,6 @@ module Configuration
add_config :enable_processing
add_config :ensure_multipart_form
add_config :delete_tmp_file_after_storage
add_config :delete_cache_id_after_storage
add_config :remove_previously_stored_files_after_update

# fog
Expand Down Expand Up @@ -145,7 +144,6 @@ def reset_config
config.store_dir = 'uploads'
config.cache_dir = 'uploads/tmp'
config.delete_tmp_file_after_storage = true
config.delete_cache_id_after_storage = true
config.remove_previously_stored_files_after_update = true
config.ignore_integrity_errors = true
config.ignore_processing_errors = true
Expand Down
4 changes: 2 additions & 2 deletions lib/carrierwave/uploader/store.rb
Expand Up @@ -58,13 +58,13 @@ def store!(new_file=nil)
with_callbacks(:store, new_file) do
new_file = storage.store!(@file)
@file.delete if delete_tmp_file_after_storage
delete_cache_id if delete_cache_id_after_storage
delete_cache_id
@file = new_file
@cache_id = nil
end
end
end

##
# Deletes a cache id (tmp dir in cache)
#
Expand Down
34 changes: 14 additions & 20 deletions spec/uploader/store_spec.rb
Expand Up @@ -104,26 +104,6 @@
@uploader.file.should_not_receive(:delete).and_return(true)
@uploader.store!
end
end

it "should delete the old cache_id" do
@uploader.cache!(@file)
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
before do
@uploader_class.delete_cache_id_after_storage = false
end

it "should not delete the old cache_id" do
@uploader.cache!(@file)
Expand All @@ -140,6 +120,20 @@
end
end

it "should delete the old cache_id" do
@uploader.cache!(@file)
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 "when the old cache_id directory is not empty" do
before do
@uploader.cache!(@file)
Expand Down

0 comments on commit 6943676

Please sign in to comment.