File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -309,6 +309,15 @@ def size
309
309
file . nil? ? 0 : file . content_length
310
310
end
311
311
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
+
312
321
##
313
322
# Check if the file exists on the remote service
314
323
#
Original file line number Diff line number Diff line change @@ -704,6 +704,32 @@ def check_file
704
704
@fog_file . copy_to ( 'uploads/new_path.jpg' )
705
705
end
706
706
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
707
733
end
708
734
end
709
735
end
You can’t perform that action at this time.
0 commit comments