开发者

How to create unit test for Paperclip::Geometry?

I'm writing unit test for a image uploader that uses paperclip. It's being bumpy and I was slowly moving thought the hurdles till I got stuck in the paperclip::geometry class

Here is my code below

 require 'test_helper'
 require File.join(File.dirname(__FILE__),"../../conf开发者_运维问答ig/initializers","paperclip")    

 class PhotoTest < ActiveSupport::TestCase
 #include ActionController::TestProcess

 should_belong_to(:product)
 should_have_attached_file :data

 setup do
   #I had to do this way because the include right below the class line was not working 
   image = Photo.create(:data => ActionController::TestUploadedFile.new(ActionController::TestCase.fixture_path + "base-production-pack.png",'image/png')) 
   @geo = Paperclip::Geometry.from_file(image)
 end
end

the paperclip::geometry is giving me the error:

test: Photo should have a paperclip attachment named #data. (PhotoTest):
Paperclip::NotIdentifiedByImageMagickError: #<Photo:0x1054aa6b8> is not recognized by the 'identify' command.
paperclip (2.3.6) lib/paperclip/geometry.rb:24:in `from_file'
/test/unit/photo_test.rb:13

I have a initializer file "paperclip.rb" that points to the identify on my local machine

Thanks in advance


Paperclip::Geometry.from_file expects a path, so you should do:

Paperclip::Geometry.from_file(image.data.path)

Sidenote: It's good that you're testing, however there's little point testing paperclip's geometry method because paperclip's test suite covers that. Your tests should cover what your code is expected to do (eg confirming thumbnails are resized as expected).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜