Using paperclip with factory girl, no image handler error
Asked Answered
G

1

8

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
Genus answered 29/11, 2012 at 14:26 Comment(0)
J
11

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
Jardine answered 13/12, 2012 at 18:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.