Permalink
Browse files

convert_options can take procs, based on code from Iffy

  • Loading branch information...
1 parent 7480516 commit 211e9883702427017d18a82f42358c11bd10c07c @jyurek jyurek committed Dec 30, 2008
Showing with 38 additions and 1 deletion.
  1. +6 −1 lib/paperclip/attachment.rb
  2. +32 −0 test/attachment_test.rb
@@ -304,7 +304,12 @@ def initialize_storage
end
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
def post_process #:nodoc:
View
@@ -138,6 +138,38 @@ class AttachmentTest < Test::Unit::TestCase
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
setup do
rebuild_model :styles => {

0 comments on commit 211e988

Please sign in to comment.