Skip to content

Commit

Permalink
Merge branch 'allow-empty-files'
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjeno committed Oct 15, 2011
2 parents 4721e74 + 4d475cc commit b381235
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/carrierwave/sanitized_file.rb
Expand Up @@ -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

##
Expand Down
26 changes: 26 additions & 0 deletions spec/sanitized_file_spec.rb
Expand Up @@ -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'))
Expand Down

0 comments on commit b381235

Please sign in to comment.