Skip to content

Commit

Permalink
Added ability for S3 bucket to be in the config file, environmentally…
Browse files Browse the repository at this point in the history
… scoped.
  • Loading branch information
Jon Yurek committed Sep 12, 2008
1 parent 457c0cd commit ce2f389
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/paperclip/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ module S3
def self.extended base
require 'right_aws'
base.instance_eval do
@bucket = @options[:bucket]
@s3_credentials = parse_credentials(@options[:s3_credentials])
@bucket = @options[:bucket] || @s3_credentials[:bucket]
@s3_options = @options[:s3_options] || {}
@s3_permissions = @options[:s3_permissions] || 'public-read'
@s3_protocol = @options[:s3_protocol] || (@s3_permissions == 'public-read' ? 'http' : 'https')
Expand Down
4 changes: 2 additions & 2 deletions test/attachment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class AttachmentTest < Test::Unit::TestCase
@not_file.expects(:to_tempfile).returns(self)
@not_file.expects(:original_filename).returns("filename.png\r\n")
@not_file.expects(:content_type).returns("image/png\r\n")
@not_file.expects(:size).returns(10)
@not_file.expects(:size).returns(10).times(2)

@dummy = Dummy.new
@attachment = @dummy.avatar
Expand Down Expand Up @@ -186,7 +186,7 @@ class AttachmentTest < Test::Unit::TestCase
@not_file.expects(:to_tempfile).returns(self)
@not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n")
@not_file.expects(:content_type).returns("image/png\r\n")
@not_file.expects(:size).returns(10)
@not_file.expects(:size).returns(10).times(2)

@dummy = Dummy.new
@attachment = @dummy.avatar
Expand Down
19 changes: 19 additions & 0 deletions test/storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ class StorageTest < Test::Unit::TestCase
end
end

context "Parsing S3 credentials with a bucket in them" do
setup do
rebuild_model :storage => :s3,
:s3_credentials => {
:production => { :bucket => "prod_bucket" },
:development => { :bucket => "dev_bucket" }
}
@dummy = Dummy.new
end

should "get the right bucket in production", :before => lambda{ ENV.expects(:[]).returns('production') } do
assert_equal "prod_bucket", @dummy.avatar.bucket_name
end

should "get the right bucket in development", :before => lambda{ ENV.expects(:[]).returns('development') } do
assert_equal "dev_bucket", @dummy.avatar.bucket_name
end
end

context "An attachment with S3 storage" do
setup do
rebuild_model :storage => :s3,
Expand Down
2 changes: 1 addition & 1 deletion test/thumbnail_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class ThumbnailTest < Test::Unit::TestCase

should "send the right command to convert when sent #make" do
@thumb.expects(:system).with do |arg|
arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}"\s+-scale\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+-strip\s+-depth\s+8\s+".*?"}
arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+"x50"\s+-crop\s+"100x50\+114\+0"\s+\+repage\s+-strip\s+-depth\s+8\s+".*?"}
end
@thumb.make
end
Expand Down

0 comments on commit ce2f389

Please sign in to comment.