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
def flush_writes
for style, file in @queued_for_write do
log("saving #{path(style)}")
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
......@@ -85,12 +93,7 @@ module Paperclip
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
......
......@@ -16,6 +16,9 @@ class FogTest < Test::Unit::TestCase
}
@connection = Fog::Storage.new(@credentials)
@connection.directories.create(
:key => @fog_directory
)
@options = {
:fog_directory => @fog_directory,
......@@ -49,16 +52,17 @@ 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
......
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