1

Possible Duplicate:
Paperclip exception : Paperclip::AdapterRegistry::NoHandlerError

**********EDIT**********

I have investigated this further and found the issue was down to the way FactoryGirl is passing the attachment. Basically the controller is receiving a string and not the uploaded file object. I have created a new question (Paperclip::Attachment passed as string when using FactoryGirl) which includes my workaround for anyone who may have a similar issue.

Testing paperclip 3.1.2 on rails 3.2.6 and i am getting the following exception when testing that a model with a file attachment is created:

test_should_create_artist(ArtistsControllerTest):
Paperclip::AdapterRegistry::NoHandlerError: No handler found for "/system/artists/photos/000/000/001/original/rails.png?1340130452"

my model is:

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

my controller is:

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

And my test is :

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

As far as i can tell the factory is working but it is:

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

As this is a basic test I'm sure I've just got something horribly wrong. Any help would be greatly appreciated! Thanks

Community
  • 1
  • 1
Dave Oh
  • 115
  • 1
  • 6

0 Answers0