From f94b0615c1b0c1000c31cd64b373dae85f0f4893 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Wed, 22 May 2019 16:05:51 +0900 Subject: [PATCH] Fix #exists? returning true after Fog file deletion Fixes #2387, Refs. bffbaaf3b5892caa96ad875a8c1655564d17ce1c --- lib/carrierwave/storage/fog.rb | 4 +++- spec/storage/fog_helper.rb | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index fb893ec14..acb1b58e9 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -242,7 +242,9 @@ def content_type=(new_content_type) # def delete # avoid a get by just using local reference - directory.files.new(:key => path).destroy + directory.files.new(:key => path).destroy.tap do |result| + @file = nil if result + end end ## diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index a24854c02..2df3f82f4 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -258,6 +258,10 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base it "should not return false for content type" do expect(@fog_file.content_type).not_to be false end + + it "should let #exists? be false" do + expect(@fog_file.exists?).to be false + end end end