Skip to content

Commit 2d1af56

Browse files
committed
Add CarrierWave::Storage::Fog::File#empty?, for consistency with SanitizedFile
Refs. #1926 (comment)
1 parent 2e8bfc0 commit 2d1af56

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/carrierwave/storage/fog.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@ def size
309309
file.nil? ? 0 : file.content_length
310310
end
311311

312+
##
313+
# === Returns
314+
#
315+
# [Boolean] whether the file is non-existent or empty
316+
#
317+
def empty?
318+
!exists? || size.zero?
319+
end
320+
312321
##
313322
# Check if the file exists on the remote service
314323
#

spec/storage/fog_helper.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,32 @@ def check_file
704704
@fog_file.copy_to('uploads/new_path.jpg')
705705
end
706706
end
707+
708+
describe '#empty?' do
709+
it "returns false when the file exists" do
710+
expect(@fog_file.empty?).to be false
711+
end
712+
713+
context "when the remote file doesn't exist" do
714+
before do
715+
@fog_file.delete
716+
end
717+
718+
it "returns true" do
719+
expect(@fog_file.empty?).to be true
720+
end
721+
end
722+
723+
context "when the remote file has no content" do
724+
before do
725+
@fog_file = @storage.store!(CarrierWave::SanitizedFile.new(StringIO.new('')))
726+
end
727+
728+
it "returns true" do
729+
expect(@fog_file.empty?).to be true
730+
end
731+
end
732+
end
707733
end
708734
end
709735
end

0 commit comments

Comments
 (0)