使用Paperclip和Factory Girl,出现无图像处理程序错误

8

我正在尝试使用factory_girl gem和paperclip进行工作,但是收到了一个“找不到处理程序”的错误信息。

test_should_update_category(CategoriesControllerTest): Paperclip::AdapterRegistry::NoHandlerError: 找不到处理程序,用于 "/system/categories/images/000/000/001/original/tel1.JPG?1354197869"

Factory girl 文件:

FactoryGirl.define do
factory :category do
name "MyString"
description "MyText"
image { File.new(File.join(Rails.root, 'test','tel1.JPG')) }
end
end

类别迁移 ::---------------
class CreateCategories < ActiveRecord::Migration
def up
create_table :categories do |t|
t.string :name
t.text :description
t.string :image

  t.timestamps
end
add_attachment :categories, :image
end

模型:

class Category < ActiveRecord::Base
attr_accessible :description, :image, :name
has_attached_file :image, :styles => { :thumb => "100x100>" }

end

分类控制器测试文件:

require 'test_helper'

class CategoriesControllerTest < ActionController::TestCase
setup do
@category = FactoryGirl.create(:category)
end
1个回答

11

我在我的应用程序/工厂中使用以下代码使其能够正常工作:

FactoryGirl.define do
  factory :upload do
    permalink "unique"
    upload Rack::Test::UploadedFile.new(Rails.root + 'spec/files/uploads/unique.jpg', 'image/jpg')
  end  
end
所以在您的应用程序中,您应该将类别的工厂更改为以下内容:
FactoryGirl.define do
  factory :category do
    name "MyString"
    description "MyText"
    image Rack::Test::UploadedFile.new(Rails.root +'test/tel1.JPG', 'image/jpg')
  end
end

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接