Commit 92e88fc3 by Pavel Pravosud Committed by Jon Yurek

Added a feature to evaluate lambdas for fog_file properties

parent 446a4cdb
......@@ -66,7 +66,16 @@ module Paperclip
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)
......
......@@ -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'
......
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