Permalink
Browse files

Added a feature to evaluate lambdas for fog_file properties

  • Loading branch information...
rwz authored and jyurek committed Nov 21, 2012
1 parent 446a4cd commit 92e88fc3946fb0732a175bdc0bf5a6dcf96ca5cf
Showing with 34 additions and 4 deletions.
  1. +10 −1 lib/paperclip/storage/fog.rb
  2. +24 −3 test/storage/fog_test.rb
@@ -66,7 +66,16 @@ def fog_credentials
end
def fog_file
- @fog_file ||= @options[:fog_file] || {}
+ @fog_file ||= begin
+ value = @options[:fog_file]
+ if !value
+ {}
+ elsif value.respond_to?(:call)
+ value.call(self)
+ else
+ value
+ end
+ end
end
def fog_public(style = default_style)
View
@@ -66,7 +66,7 @@ class FogTest < Test::Unit::TestCase
@dummy.avatar.path
end
end
-
+
context "with no path or url given and using defaults" do
setup do
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
@@ -82,14 +82,35 @@ class FogTest < Test::Unit::TestCase
@dummy.id = 1
@dummy.avatar = @file
end
-
+
teardown { @file.close }
-
+
should "have correct path and url from interpolated defaults" do
assert_equal "dummies/avatars/000/000/001/original/5k.png", @dummy.avatar.path
end
end
+ context "with file params provided as lambda" do
+ setup do
+ fog_file = lambda{ |a| { :custom_header => a.instance.custom_method }}
+ klass = rebuild_model :storage => :fog,
+ :fog_file => fog_file
+
+ klass.class_eval do
+ def custom_method
+ 'foobar'
+ end
+ end
+
+
+ @dummy = Dummy.new
+ end
+
+ should "be able to evaluate correct values for file headers" do
+ assert_equal @dummy.avatar.send(:fog_file), { :custom_header => 'foobar' }
+ end
+ end
+
setup do
@fog_directory = 'papercliptests'

0 comments on commit 92e88fc

Please sign in to comment.