samedi 23 janvier 2016

Trouble with Paperclip + Rspec ( Paperclip::AdapterRegistry::NoHandlerError: No handler found for )

I'm having some problems when i'm trying to run some tests with rspec and paperclip.

i'm getting this message:

Failure/Error: @event = Event.new(event_params)

     Paperclip::AdapterRegistry::NoHandlerError:
       No handler found for "/events/rails.png?1453566649"

Here is my test class:

context "user creates a new event" do describe "with valid fields" do

  before(:each) do
    @image = Rack::Test::UploadedFile.new(Rails.root.join('spec/images/rails.png'), 'image/png')
  end

  it "must persist the event" do
    event = build(:event, photo: nil, photo_attachment: nil)
    event.photo_attachment = @image
    post :create, event: {title: event.title, description: event.description, place: event.place, address: event.address, opening_date: event.opening_date, category: event.category, price: event.price, photo_attachment: event.photo_attachment, hour: event. hour}
    expect(assigns(:event).id.nil?).to be false
  end

Here is my controller:

class EventsController < ApplicationController

  def new
    @event = Event.new
  end

  def create
    @event = Event.new(event_params)

    if @event.save
      redirect_to "success"
    end
  end

  private

  def event_params
    params.require(:event).permit(:title, :description, :photo, :place, :address, :opening_date, :ending_date, :category, :price, :photo_attachment, :hour)
  end
end

And here is my factory ( I'm using factory girl ):

FactoryGirl.define do
  factory :event do
    title { Faker::Name.name }
    description 'A simples description'
    photo { Faker::Bitcoin.address }
    place 'Anywhere'
    address { Faker::Address.street_address }
    opening_date Date.today
    ending_date Faker::Date.forward(2)
    category 'any category'
    price 1.99
    photo_attachment {File.new("#{Rails.root}/spec/images/rails.png")}
    hour '00:00'
  end

  trait :soccer_game do
    title 'Soccer Game'
    place 'Maracana Stadium'
    opening_date Date.today
    hour '14:00'
  end

end

Could you help me with this ?

Aucun commentaire:

Enregistrer un commentaire