Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using paperclip with factory girl, no image handler error

I am trying to use paperclip with factory_girl gem but getting a "no handler found error" message.

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

Factory girl file:

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

category migration ::---------------

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

model:

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

end

category controller test file:

require 'test_helper'

class CategoriesControllerTest < ActionController::TestCase
setup do
@category = FactoryGirl.create(:category)
end
like image 675
Sanjeev Avatar asked Nov 29 '12 14:11

Sanjeev


1 Answers

I make it to work with the following code in my app / factory:

FactoryGirl.define do
  factory :upload do
    permalink "unique"
    upload Rack::Test::UploadedFile.new(Rails.root + 'spec/files/uploads/unique.jpg', 'image/jpg')
  end  
end

So in your app you should change your factory of category to something like this:

FactoryGirl.define do
  factory :category do
    name "MyString"
    description "MyText"
    image Rack::Test::UploadedFile.new(Rails.root +'test/tel1.JPG', 'image/jpg')
  end
end
like image 133
JohnDel Avatar answered Oct 21 '22 20:10

JohnDel