Permalink
Browse files

Merge pull request #468 from chrisdurtschi/fog_streaming_upload

Fog streaming upload
  • Loading branch information...
bensie committed Sep 23, 2011
2 parents 2a1d3fc + 1c48854 commit ba8b9d4de5519a367d7731662d8efa8472c2f999
Showing with 227 additions and 127 deletions.
  1. +12 −0 lib/carrierwave/sanitized_file.rb
  2. +2 −1 lib/carrierwave/storage/fog.rb
  3. +32 −0 spec/sanitized_file_spec.rb
  4. +181 −126 spec/storage/fog_helper.rb
@@ -216,6 +216,18 @@ def delete
FileUtils.rm(self.path) if exists?
end
+ ##
+ # Returns a File object, or nil if it does not exist.
+ #
+ # === Returns
+ #
+ # [File] a File object representing the SanitizedFile
+ #
+ def to_file
+ return @file if @file.is_a?(File)
+ File.open(path) if exists?
+ end
+
##
# Returns the content type of the file.
#
@@ -225,9 +225,10 @@ def size
#
# [Boolean] true on success or raises error
def store(new_file)
+ fog_file = new_file.to_file
@content_type ||= new_file.content_type
@file = directory.files.create({
- :body => new_file.read,
+ :body => fog_file ? fog_file : new_file.read,
:content_type => @content_type,
:key => path,
:public => @uploader.fog_public
@@ -383,6 +383,20 @@
File.exists?(@sanitized_file.path).should be_false
end
end
+
+ describe '#to_file' do
+ it "should return a File object" do
+ @sanitized_file.to_file.should be_a(File)
+ end
+
+ it "should have the same path as the SanitizedFile" do
+ @sanitized_file.to_file.path.should == @sanitized_file.path
+ end
+
+ it "should have the same contents as the SantizedFile" do
+ @sanitized_file.to_file.read.should == @sanitized_file.read
+ end
+ end
end
describe "with a valid Hash" do
@@ -470,6 +484,12 @@
end
end
+ describe '#to_file' do
+ it "should be nil" do
+ @sanitized_file.to_file.should be_nil
+ end
+ end
+
end
describe "with a valid File object" do
@@ -614,6 +634,12 @@
running { @empty.delete }.should_not raise_error
end
end
+
+ describe '#to_file' do
+ it "should be nil" do
+ @empty.to_file.should be_nil
+ end
+ end
end
describe "that is an empty string" do
@@ -680,6 +706,12 @@
running { @empty.delete }.should_not raise_error
end
end
+
+ describe '#to_file' do
+ it "should be nil" do
+ @empty.to_file.should be_nil
+ end
+ end
end
end
Oops, something went wrong.

0 comments on commit ba8b9d4

Please sign in to comment.