2012-11-29 18 views
8

我想用factory_girl寶石回形針但得到「沒有處理程序發現 錯誤」消息。與工廠女孩一起使用回形針,沒有圖像處理程序錯誤

test_should_update_category(CategoriesControllerTest): Paperclip::AdapterRegistry::NoHandlerError: No handler found for "/system/categories/images/000/000/001/original/tel1.JPG?1354197869"

工廠女孩文件:

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 

回答

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