From 19c97c7e35c1d1acbdfd8fd1abac36c1495ef78a Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Tue, 18 Jun 2019 16:40:08 +0900 Subject: [PATCH] Allow deleting all files for multiple file upload. Fixes #1990 --- lib/carrierwave/mounter.rb | 2 +- spec/mount_multiple_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/carrierwave/mounter.rb b/lib/carrierwave/mounter.rb index 6b18fdccf..2ebe89dea 100644 --- a/lib/carrierwave/mounter.rb +++ b/lib/carrierwave/mounter.rb @@ -41,7 +41,7 @@ def uploaders end def cache(new_files) - return if new_files.blank? + return if !new_files.is_a?(Array) && new_files.blank? old_uploaders = uploaders @uploaders = new_files.map do |new_file| handle_error do diff --git a/spec/mount_multiple_spec.rb b/spec/mount_multiple_spec.rb index eea5435fd..20725b315 100644 --- a/spec/mount_multiple_spec.rb +++ b/spec/mount_multiple_spec.rb @@ -309,6 +309,16 @@ def monkey expect { instance.store_images! }.not_to raise_error expect(instance.images.map(&:identifier)).to be_empty end + + it "allows deleting all files" do + instance.images = [] + expect(instance.images.map(&:identifier)).to be_empty + end + + it "allows assignment of uploader instances" do + instance.images = [instance.images[0]] + expect(instance.images.map(&:identifier)).to eq ['bork.txt'] + end end end