Commit 211e9883 by Jon Yurek

convert_options can take procs, based on code from Iffy

parent 7480516a
...@@ -304,7 +304,12 @@ module Paperclip ...@@ -304,7 +304,12 @@ module Paperclip
end end
def extra_options_for(style) #:nodoc: def extra_options_for(style) #:nodoc:
[ convert_options[style], convert_options[:all] ].compact.join(" ") all_options = convert_options[:all]
all_options = all_options.call(instance) if all_options.respond_to?(:call)
style_options = convert_options[style]
style_options = style_options.call(instance) if style_options.respond_to?(:call)
[ style_options, all_options ].compact.join(" ")
end end
def post_process #:nodoc: def post_process #:nodoc:
......
...@@ -138,6 +138,38 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -138,6 +138,38 @@ class AttachmentTest < Test::Unit::TestCase
end end
end end
context "An attachment with :convert_options that is a proc" do
setup do
rebuild_model :styles => {
:thumb => "100x100",
:large => "400x400"
},
:convert_options => {
:all => lambda{|i| i.all },
:thumb => lambda{|i| i.thumb }
}
Dummy.class_eval do
def all; "-all"; end
def thumb; "-thumb"; end
end
@dummy = Dummy.new
@dummy.avatar
end
should "report the correct options when sent #extra_options_for(:thumb)" do
assert_equal "-thumb -all", @dummy.avatar.send(:extra_options_for, :thumb), @dummy.avatar.convert_options.inspect
end
should "report the correct options when sent #extra_options_for(:large)" do
assert_equal "-all", @dummy.avatar.send(:extra_options_for, :large)
end
before_should "call extra_options_for(:thumb/:large)" do
Paperclip::Attachment.any_instance.expects(:extra_options_for).with(:thumb)
Paperclip::Attachment.any_instance.expects(:extra_options_for).with(:large)
end
end
context "An attachment with both 'normal' and hash-style styles" do context "An attachment with both 'normal' and hash-style styles" do
setup do setup do
rebuild_model :styles => { rebuild_model :styles => {
......
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