8

factory_girl gem で paperclip を使用しようとしていますが、「ハンドラが見つかりません」というメッセージが表示されます。

test_should_update_category(CategoriesControllerTest): Paperclip::AdapterRegistry::NoHandlerError: "/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
4

1 に答える 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
于 2012-12-13T18:12:44.457 に答える