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
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 @@ module Paperclip
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
......
......@@ -618,6 +618,21 @@ class S3Test < Test::Unit::TestCase
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,
......
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