Skip to content
Browse files

Merge branch 'fog_patches' of https://github.com/kickstarter/paperclip

  • Loading branch information...
2 parents db11fca + be08b80 commit 03560dc17c8e2dc683ad37db8680e4cb4dbe2f77 @mike-burns mike-burns committed Jun 30, 2011
Showing with 31 additions and 34 deletions.
  1. +15 −11 lib/paperclip/storage/fog.rb
  2. +16 −23 test/fog_test.rb
View
26 lib/paperclip/storage/fog.rb
@@ -45,6 +45,7 @@ def self.extended base
@fog_credentials = @options[:fog_credentials]
@fog_host = @options[:fog_host]
@fog_public = @options[:fog_public]
+ @fog_file = @options[:fog_file] || {}
@url = ':fog_public_url'
Paperclip.interpolates(:fog_public_url) do |attachment, style|
@@ -64,11 +65,19 @@ def exists?(style = default_style)
def flush_writes
for style, file in @queued_for_write do
log("saving #{path(style)}")
- directory.files.create(
- :body => file,
- :key => path(style),
- :public => @fog_public
- )
+ retried = false
+ begin
+ directory.files.create(@fog_file.merge(
+ :body => file,
+ :key => path(style),
+ :public => @fog_public
+ ))
+ rescue Excon::Errors::NotFound
+ raise if retried
+ retried = true
+ directory.save
+ retry
+ end
end
@queued_for_write = {}
end
@@ -115,12 +124,7 @@ def connection
end
def directory
- @directory ||= begin
- connection.directories.get(@fog_directory) || connection.directories.create(
- :key => @fog_directory,
- :public => @fog_public
- )
- end
+ @directory ||= connection.directories.new(:key => @fog_directory)
end
end
View
39 test/fog_test.rb
@@ -16,15 +16,21 @@ class FogTest < Test::Unit::TestCase
}
@connection = Fog::Storage.new(@credentials)
+ @connection.directories.create(
+ :key => @fog_directory
+ )
- rebuild_model(
+ @options = {
:fog_directory => @fog_directory,
:fog_credentials => @credentials,
:fog_host => nil,
:fog_public => true,
+ :fog_file => {:cache_control => 1234},
:path => ":attachment/:basename.:extension",
:storage => :fog
- )
+ }
+
+ rebuild_model(@options)
end
should "be extended by the Fog module" do
@@ -46,31 +52,25 @@ class FogTest < Test::Unit::TestCase
end
context "without a bucket" do
- should "succeed" do
+ setup do
+ @connection.directories.get(@fog_directory).destroy
+ end
+
+ should "create the bucket" do
assert @dummy.save
+ assert @connection.directories.get(@fog_directory)
end
end
context "with a bucket" do
- setup do
- @connection.directories.create(:key => @fog_directory)
- end
-
should "succeed" do
assert @dummy.save
end
end
context "without a fog_host" do
setup do
- rebuild_model(
- :fog_directory => @fog_directory,
- :fog_credentials => @credentials,
- :fog_host => nil,
- :fog_public => true,
- :path => ":attachment/:basename.:extension",
- :storage => :fog
- )
+ rebuild_model(@options.merge(:fog_host => nil))
@dummy = Dummy.new
@dummy.avatar = StringIO.new('.')
@dummy.save
@@ -83,14 +83,7 @@ class FogTest < Test::Unit::TestCase
context "with a fog_host" do
setup do
- rebuild_model(
- :fog_directory => @fog_directory,
- :fog_credentials => @credentials,
- :fog_host => 'http://example.com',
- :fog_public => true,
- :path => ":attachment/:basename.:extension",
- :storage => :fog
- )
+ rebuild_model(@options.merge(:fog_host => 'http://example.com'))
@dummy = Dummy.new
@dummy.avatar = StringIO.new('.')
@dummy.save

0 comments on commit 03560dc

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