Skip to content
Browse files

Added tests for passing S3 credentials as a proc.

Fixes #738
  • Loading branch information...
1 parent 72ed6a8 commit b89044fe49ca66d538b143b6f998cbc31bb36c34 @beachbc beachbc committed with sikachu
Showing with 17 additions and 1 deletion.
  1. +2 −1 lib/paperclip/storage/s3.rb
  2. +15 −0 test/storage/s3_test.rb
View
3 lib/paperclip/storage/s3.rb
@@ -234,6 +234,7 @@ def set_permissions permissions
end
def parse_credentials creds
+ creds = creds.respond_to?('call') ? creds.call(self) : creds
creds = find_credentials(creds).stringify_keys
env = Object.const_defined?(:Rails) ? Rails.env : nil
(creds[env] || creds).symbolize_keys
@@ -333,7 +334,7 @@ def find_credentials creds
when Hash
creds
else
- raise ArgumentError, "Credentials are not a path, file, or hash."
+ raise ArgumentError, "Credentials are not a path, file, proc, or hash."
end
end
private :find_credentials
View
15 test/storage/s3_test.rb
@@ -618,6 +618,21 @@ def counter
end
end
+ context "An attachment with S3 storage and S3 credentials defined as a Proc" do
+ setup do
+ rebuild_model :storage => :s3,
+ :bucket => {:not => :important},
+ :s3_credentials => lambda { |attachment|
+ Hash['access_key_id' => "access#{attachment.instance.other}", 'secret_access_key' => "secret#{attachment.instance.other}"]
+ }
+ end
+
+ should "get the right credentials" do
+ assert "access1234", Dummy.new(:other => '1234').avatar.s3_credentials[:access_key_id]
+ assert "secret1234", Dummy.new(:other => '1234').avatar.s3_credentials[:secret_access_key]
+ end
+ end
+
context "An attachment with S3 storage and specific s3 headers set" do
setup do
rebuild_model :storage => :s3,

0 comments on commit b89044f

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