Commit b89044fe by beachbc Committed by Prem Sichanugrist

Added tests for passing S3 credentials as a proc.

Fixes #738
parent 72ed6a8e
...@@ -234,6 +234,7 @@ module Paperclip ...@@ -234,6 +234,7 @@ module Paperclip
end end
def parse_credentials creds def parse_credentials creds
creds = creds.respond_to?('call') ? creds.call(self) : creds
creds = find_credentials(creds).stringify_keys creds = find_credentials(creds).stringify_keys
env = Object.const_defined?(:Rails) ? Rails.env : nil env = Object.const_defined?(:Rails) ? Rails.env : nil
(creds[env] || creds).symbolize_keys (creds[env] || creds).symbolize_keys
...@@ -333,7 +334,7 @@ module Paperclip ...@@ -333,7 +334,7 @@ module Paperclip
when Hash when Hash
creds creds
else else
raise ArgumentError, "Credentials are not a path, file, or hash." raise ArgumentError, "Credentials are not a path, file, proc, or hash."
end end
end end
private :find_credentials private :find_credentials
......
...@@ -618,6 +618,21 @@ class S3Test < Test::Unit::TestCase ...@@ -618,6 +618,21 @@ class S3Test < Test::Unit::TestCase
end end
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 context "An attachment with S3 storage and specific s3 headers set" do
setup do setup do
rebuild_model :storage => :s3, rebuild_model :storage => :s3,
......
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