Commit 87426153 by Benjamin Hüttinger Committed by Benjamin Hüttinger

allow proc for fog_credentials

parent 2b562a9b
......@@ -163,8 +163,10 @@ module Paperclip
YAML::load(ERB.new(File.read(creds)).result)
when Hash
creds
when Proc
creds.call(self)
else
raise ArgumentError, "Credentials are not a path, file, or hash."
raise ArgumentError, "Credentials are not a path, file, hash or proc."
end
end
......
......@@ -249,6 +249,25 @@ class FogTest < Test::Unit::TestCase
assert_match /http:\/\/dynamicfoghost\.com/, @dummy.avatar.url
end
end
context "with a proc for the fog_credentials evaluating a model method" do
setup do
@dynamic_fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'DYNAMIC_ID',
:aws_secret_access_key => 'DYNAMIC_SECRET'
}
rebuild_model(@options.merge(:fog_credentials => lambda { |attachment| attachment.instance.fog_credentials }))
@dummy = Dummy.new
@dummy.stubs(:fog_credentials).returns(@dynamic_fog_credentials)
@dummy.avatar = @file
@dummy.save
end
should "provide a public url" do
assert_equal @dummy.avatar.fog_credentials, @dynamic_fog_credentials
end
end
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