Skip to content
Browse files

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

… scoped.
  • Loading branch information...
1 parent 457c0cd commit ce2f389a7539b2501557f57fab6536a9cc79cb88 @jyurek jyurek committed Sep 12, 2008
Showing with 23 additions and 4 deletions.
  1. +1 −1 lib/paperclip/storage.rb
  2. +2 −2 test/attachment_test.rb
  3. +19 −0 test/storage_test.rb
  4. +1 −1 test/thumbnail_test.rb
View
2 lib/paperclip/storage.rb
@@ -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')
View
4 test/attachment_test.rb
@@ -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
@@ -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
View
19 test/storage_test.rb
@@ -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,
View
2 test/thumbnail_test.rb
@@ -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

0 comments on commit ce2f389

Please sign in to comment.
Something went wrong with that request. Please try again.