当我尝试使用rspec和paperclip进行一些测试时,我遇到了一些问题。
我收到此消息:
Failure/Error: @event = Event.new(event_params)
Paperclip::AdapterRegistry::NoHandlerError:
No handler found for "/events/rails.png?1453566649"
这是我的测试类:
context“用户创建一个新事件” 描述“有效字段”做
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
这是我的控制器:
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
这是我的工厂(我正在使用工厂女孩):
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
你能帮我解决这个问题吗?