Skip to content
Browse files

Sanitized file accepting an empty file

  • Loading branch information...
1 parent a09a36e commit 4d475cc7f1042dd10da20bf47cf8600c148a4c79 @Arjeno committed Oct 15, 2011
Showing with 27 additions and 1 deletion.
  1. +1 −1 lib/carrierwave/sanitized_file.rb
  2. +26 −0 spec/sanitized_file_spec.rb
View
2 lib/carrierwave/sanitized_file.rb
@@ -132,7 +132,7 @@ def is_path?
# [Boolean] whether the file is valid and has a non-zero size
#
def empty?
- @file.nil? || self.size.nil? || (self.size.zero? && ! self.file.is_a?(File))
+ @file.nil? || self.size.nil? || (self.size.zero? && ! self.exists?)
end
##
View
26 spec/sanitized_file_spec.rb
@@ -509,7 +509,33 @@
end
end
+
+ describe "with a valid File object and an empty file" do
+ before do
+ FileUtils.cp(file_path('test.jpg'), file_path('llama.jpg'))
+ FileUtils.rm file_path('llama.jpg')
+ FileUtils.touch file_path('llama.jpg')
+ @sanitized_file = CarrierWave::SanitizedFile.new(stub_file('llama.jpg', 'image/jpeg'))
+ @sanitized_file.should_not be_empty
+ end
+ it_should_behave_like "all valid sanitized files that are stored on disk"
+
+ describe '#is_path?' do
+ it "should be false" do
+ @sanitized_file.is_path?.should be_false
+ end
+ end
+
+ describe '#path' do
+ it "should return the path of the file" do
+ @sanitized_file.path.should_not be_nil
+ @sanitized_file.path.should == file_path('llama.jpg')
+ end
+ end
+
+ end
+
describe "with a valid path" do
before do
FileUtils.cp(file_path('test.jpg'), file_path('llama.jpg'))

0 comments on commit 4d475cc

Please sign in to comment.
Something went wrong with that request. Please try again.