Commit ce2f389a by Jon Yurek

Added ability for S3 bucket to be in the config file, environmentally scoped.

parent 457c0cd5
...@@ -105,8 +105,8 @@ module Paperclip ...@@ -105,8 +105,8 @@ module Paperclip
def self.extended base def self.extended base
require 'right_aws' require 'right_aws'
base.instance_eval do base.instance_eval do
@bucket = @options[:bucket]
@s3_credentials = parse_credentials(@options[:s3_credentials]) @s3_credentials = parse_credentials(@options[:s3_credentials])
@bucket = @options[:bucket] || @s3_credentials[:bucket]
@s3_options = @options[:s3_options] || {} @s3_options = @options[:s3_options] || {}
@s3_permissions = @options[:s3_permissions] || 'public-read' @s3_permissions = @options[:s3_permissions] || 'public-read'
@s3_protocol = @options[:s3_protocol] || (@s3_permissions == 'public-read' ? 'http' : 'https') @s3_protocol = @options[:s3_protocol] || (@s3_permissions == 'public-read' ? 'http' : 'https')
......
...@@ -156,7 +156,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -156,7 +156,7 @@ class AttachmentTest < Test::Unit::TestCase
@not_file.expects(:to_tempfile).returns(self) @not_file.expects(:to_tempfile).returns(self)
@not_file.expects(:original_filename).returns("filename.png\r\n") @not_file.expects(:original_filename).returns("filename.png\r\n")
@not_file.expects(:content_type).returns("image/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 @dummy = Dummy.new
@attachment = @dummy.avatar @attachment = @dummy.avatar
...@@ -186,7 +186,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -186,7 +186,7 @@ class AttachmentTest < Test::Unit::TestCase
@not_file.expects(:to_tempfile).returns(self) @not_file.expects(:to_tempfile).returns(self)
@not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n") @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(:content_type).returns("image/png\r\n")
@not_file.expects(:size).returns(10) @not_file.expects(:size).returns(10).times(2)
@dummy = Dummy.new @dummy = Dummy.new
@attachment = @dummy.avatar @attachment = @dummy.avatar
......
...@@ -42,6 +42,25 @@ class StorageTest < Test::Unit::TestCase ...@@ -42,6 +42,25 @@ class StorageTest < Test::Unit::TestCase
end end
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 context "An attachment with S3 storage" do
setup do setup do
rebuild_model :storage => :s3, rebuild_model :storage => :s3,
......
...@@ -119,7 +119,7 @@ class ThumbnailTest < Test::Unit::TestCase ...@@ -119,7 +119,7 @@ class ThumbnailTest < Test::Unit::TestCase
should "send the right command to convert when sent #make" do should "send the right command to convert when sent #make" do
@thumb.expects(:system).with do |arg| @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 end
@thumb.make @thumb.make
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