test/attachment_test.rb in thoughtbot-paperclip-2.2.0 vs test/attachment_test.rb in thoughtbot-paperclip-2.2.1
- old
+ new
@@ -136,10 +136,42 @@
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 :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 => {
:normal => ["50x50#", :png],
:hash => { :geometry => "50x50#", :format => :png }
@@ -264,14 +296,16 @@
context "Attachment with strange letters" do
setup do
rebuild_model
@not_file = mock
+ @tempfile = mock
@not_file.stubs(:nil?).returns(false)
- @not_file.expects(:to_tempfile).returns(self)
+ @not_file.expects(:size).returns(10)
+ @tempfile.expects(:size).returns(10)
+ @not_file.expects(:to_tempfile).returns(@tempfile)
@not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n")
@not_file.expects(:content_type).returns("image/png\r\n")
- @not_file.expects(:size).returns(10).times(2)
@dummy = Dummy.new
@attachment = @dummy.avatar
@attachment.expects(:valid_assignment?).with(@not_file).returns(true)
@attachment.expects(:queue_existing_for_delete)