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 ...@@ -66,7 +66,16 @@ module Paperclip
end end
def fog_file 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 end
def fog_public(style = default_style) def fog_public(style = default_style)
......
...@@ -66,7 +66,7 @@ class FogTest < Test::Unit::TestCase ...@@ -66,7 +66,7 @@ class FogTest < Test::Unit::TestCase
@dummy.avatar.path @dummy.avatar.path
end end
end end
context "with no path or url given and using defaults" do context "with no path or url given and using defaults" do
setup do setup do
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" }, rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
...@@ -82,14 +82,35 @@ class FogTest < Test::Unit::TestCase ...@@ -82,14 +82,35 @@ class FogTest < Test::Unit::TestCase
@dummy.id = 1 @dummy.id = 1
@dummy.avatar = @file @dummy.avatar = @file
end end
teardown { @file.close } teardown { @file.close }
should "have correct path and url from interpolated defaults" do should "have correct path and url from interpolated defaults" do
assert_equal "dummies/avatars/000/000/001/original/5k.png", @dummy.avatar.path assert_equal "dummies/avatars/000/000/001/original/5k.png", @dummy.avatar.path
end end
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 setup do
@fog_directory = 'papercliptests' @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