重複の可能性:
Paperclip の例外: Paperclip::AdapterRegistry::NoHandlerError
**********編集**********
これをさらに調査したところ、問題は FactoryGirl が添付ファイルを渡す方法にあることがわかりました。基本的に、コントローラーはアップロードされたファイル オブジェクトではなく、文字列を受け取ります。同様の問題を抱えている可能性のある人のための回避策を含む新しい質問 ( Paperclip::Attachment は、FactoryGirl を使用するときに文字列として渡されます) を作成しました。
Rails 3.2.6 で paperclip 3.1.2 をテストしています。ファイルが添付されたモデルが作成されていることをテストすると、次の例外が発生します。
test_should_create_artist(ArtistsControllerTest):
Paperclip::AdapterRegistry::NoHandlerError: No handler found for "/system/artists/photos/000/000/001/original/rails.png?1340130452"
私のモデルは:
class Artist < ActiveRecord::Base
has_attached_file :photo, :styles => {:medium => "300x300>", :thumb => "100x100>" }, :default_url => "image_missing.png"
attr_accessible :photo, :photo_file_name
validates_attachment :photo, :presence => true, :content_type => { :content_type => "image/jpg" }, :size => { :in => 0..10000.kilobytes }
end
私のコントローラーは:
class ArtistsController < ApplicationController
# POST /artists
# POST /artists.json
def create
@artist = Artist.new(params[:artist])
respond_to do |format|
if @artist.save
format.html { redirect_to @artist, notice: 'Artist was successfully created.' }
format.json { render json: @artist, status: :created, location: @artist }
else
format.html { render action: "new" }
format.json { render json: @artist.errors, status: :unprocessable_entity }
end
end
end
end
そして私のテストは:
require 'test_helper'
class ArtistsControllerTest < ActionController::TestCase
setup do
@artist = FactoryGirl.build(:artist)
end
test "should create artist" do
assert_difference('Artist.count') do
post :create, :artist => { biography: @artist.biography, name: @artist.name, website: @artist.website, photo: @artist.photo }, :html => { :multipart => true }
end
assert_redirected_to artist_path(assigns(:artist))
end
end
私が知る限り、工場は稼働していますが、次のとおりです。
include ActionDispatch::TestProcess
FactoryGirl.define do
factory :artist do
id 1
photo {fixture_file_upload(Rails.root.join('test','fixtures', 'files', 'rails.png'),'image/png')}
end
end
これは基本的なテストなので、何かひどく間違っていると確信しています。どんな助けでも大歓迎です!ありがとう