Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the cache_only configuration option #1456

Merged
merged 1 commit into from Sep 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/carrierwave/uploader/configuration.rb
Expand Up @@ -38,6 +38,7 @@ module Configuration
add_config :validate_processing
add_config :validate_download
add_config :mount_on
add_config :cache_only

# set default values
reset_config
Expand Down
2 changes: 1 addition & 1 deletion lib/carrierwave/uploader/store.rb
Expand Up @@ -54,7 +54,7 @@ def store_path(for_file=filename)
#
def store!(new_file=nil)
cache!(new_file) if new_file && ((@cache_id != parent_cache_id) || @cache_id.nil?)
if @file and @cache_id
if !cache_only and @file and @cache_id
with_callbacks(:store, new_file) do
new_file = storage.store!(@file)
if delete_tmp_file_after_storage
Expand Down
29 changes: 29 additions & 0 deletions spec/uploader/store_spec.rb
Expand Up @@ -102,6 +102,35 @@
@uploader.store!
end

context "with the cache_only option set to true" do
before do
@uploader_class.cache_only = true
end

it "should not instruct the storage engine to store the file" do
@uploader.cache!(@file)
@storage.should_not_receive(:store!)
@uploader.store!
end

it "should still be cached" do
@uploader.store!(@file)
@uploader.should be_cached
end

it "should not reset the cache_name" do
@uploader.cache!(@file)
@uploader.store!
@uploader.cache_name.should_not be_nil
end

it "should not delete the old file" do
@uploader.cache!(@file)
@uploader.file.should_not_receive(:delete)
@uploader.store!
end
end

context "with the delete_tmp_file_after_storage option set to false" do
before do
@uploader_class.delete_tmp_file_after_storage = false
Expand Down