Commit be08b80e by Lance Ivy

don't needlessly retrieve directory and contents from fog provider. create the…

don't needlessly retrieve directory and contents from fog provider. create the directory only when it's needed.
parent 48293005
...@@ -35,11 +35,19 @@ module Paperclip ...@@ -35,11 +35,19 @@ module Paperclip
def flush_writes def flush_writes
for style, file in @queued_for_write do for style, file in @queued_for_write do
log("saving #{path(style)}") log("saving #{path(style)}")
retried = false
begin
directory.files.create(@fog_file.merge( directory.files.create(@fog_file.merge(
:body => file, :body => file,
:key => path(style), :key => path(style),
:public => @fog_public :public => @fog_public
)) ))
rescue Excon::Errors::NotFound
raise if retried
retried = true
directory.save
retry
end
end end
@queued_for_write = {} @queued_for_write = {}
end end
...@@ -85,12 +93,7 @@ module Paperclip ...@@ -85,12 +93,7 @@ module Paperclip
end end
def directory def directory
@directory ||= begin @directory ||= connection.directories.new(:key => @fog_directory)
connection.directories.get(@fog_directory) || connection.directories.create(
:key => @fog_directory,
:public => @fog_public
)
end
end end
end end
......
...@@ -16,6 +16,9 @@ class FogTest < Test::Unit::TestCase ...@@ -16,6 +16,9 @@ class FogTest < Test::Unit::TestCase
} }
@connection = Fog::Storage.new(@credentials) @connection = Fog::Storage.new(@credentials)
@connection.directories.create(
:key => @fog_directory
)
@options = { @options = {
:fog_directory => @fog_directory, :fog_directory => @fog_directory,
...@@ -49,16 +52,17 @@ class FogTest < Test::Unit::TestCase ...@@ -49,16 +52,17 @@ class FogTest < Test::Unit::TestCase
end end
context "without a bucket" do 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 @dummy.save
assert @connection.directories.get(@fog_directory)
end end
end end
context "with a bucket" do context "with a bucket" do
setup do
@connection.directories.create(:key => @fog_directory)
end
should "succeed" do should "succeed" do
assert @dummy.save assert @dummy.save
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment