如何为Paperclip :: Geometry创建单元测试?

时间:2011-01-06 04:57:27

标签: ruby-on-rails unit-testing paperclip shoulda

我正在为使用回形针的图像上传器编写单元测试。 这是崎岖不平的,我正在慢慢地想着障碍,直到我被困在paperclip :: geometry class

以下是我的代码

 require 'test_helper'
 require File.join(File.dirname(__FILE__),"../../config/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

paperclip :: geometry给出了错误:

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

我有一个初始化文件“paperclip.rb”,它指向我本地计算机上的标识

提前致谢

1 个答案:

答案 0 :(得分:2)

Paperclip::Geometry.from_file需要一条路径,所以你应该这样做:

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

旁注:你正在测试它是好的,但是测量回形针的几何方法几乎没有意义,因为回形针的测试套件涵盖了这一点。您的测试应涵盖您的代码预期要做的事情(例如确认缩略图按预期调整大小)。