Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
Look for existing S3 bucket before creating a new one (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
knowuh committed Jun 4, 2015
1 parent 63a9844 commit 3190e82
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/shutterbug/storage/s3_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def self.create_bin
:public => true)
end

def self.lookup_bin
self.connection.directories.get(Configuration.instance.s3_bin) || self.create_bin
end

def self.s3_bin
@s3_bin ||= self.create_bin
end
Expand Down
44 changes: 42 additions & 2 deletions spec/shutterbug/s3_storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,51 @@
require 'fog'

describe Shutterbug::Storage::S3Storage do
let(:mock_write_result) { mock(:public_url => "http://amazon.cloud/url.png")}
let(:s3_bin) { nil }
let(:storage) { Shutterbug::Storage::S3Storage}
let(:mock_write_result) { double(:public_url => "http://amazon.cloud/url.png")}
before(:each) do
Shutterbug::Storage::S3Storage.stub!(:write => mock_write_result)
storage.stub(:write => mock_write_result)
end

it_behaves_like "a storage provider" do
end

describe "some class methods" do
before(:each) do
Fog.mock!
end
describe "s3_bin" do
subject do
storage
end
describe "when the bin is already configured" do
let(:fake_bin) { "xyzzy" }
it "should not call #lookup_bin or #create_bin" do
subject.instance_variable_set(:@s3_bin, fake_bin)
subject.should_not_receive(:lookup_bin)
subject.should_not_receive(:create_bin)
subject.s3_bin.should eq fake_bin
# reset
subject.instance_variable_set(:@s3_bin,nil)
end
end
describe "when the bin can't be found" do
let(:fake_bin) { "xyzzy" }
it "should call #create_bin" do
subject.stub_chain(:connection,:directories,:get).and_return(nil)
subject.should_receive(:create_bin).and_return(fake_bin)
subject.s3_bin.should eq fake_bin
end
end
describe "when the bin exists" do
let(:fake_bin) { "xyzzy" }
it "should not call #create_bin" do
subject.stub_chain(:connection,:directories,:get).and_return(fake_bin)
subject.s3_bin.should eq fake_bin
end
end
end
end
end

0 comments on commit 3190e82

Please sign in to comment.