Permalink
Browse files

allow proc for fog_credentials

  • Loading branch information...
1 parent 2b562a9 commit 87426153fead3f6555f33bccf41a623d330da9bc @maxigs maxigs committed with maxigs Jan 19, 2012
Showing with 22 additions and 1 deletion.
  1. +3 −1 lib/paperclip/storage/fog.rb
  2. +19 −0 test/storage/fog_test.rb
@@ -163,8 +163,10 @@ def find_credentials(creds)
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
View
@@ -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

0 comments on commit 8742615

Please sign in to comment.