本文介绍了带有载波上传字段的工厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我需要为我的模型建立工厂,例如
Hello i need to build up Factory for my model, for example
Factory.define :farm do |f|
f.name { Factory.next :name }
f.harvest '3'
f.offers 'Random'
f.latitude '43'
f.longitude '-70'
f.about 'We rocks!'
f.logo { Factory.next :logo } # this doesn't work
end
现在我只是将字符串#{n}.jpg"传递到我的徽标字段中,这不起作用,如何评估该字段?我使用 CarrierWave 上传.
For now im just pass string "#{n}.jpg" into my logo field and this dont work, how to evalute this field? Im using CarrierWave for uploading.
推荐答案
您需要在您的工厂 (Rails 3) 中包含 ActionDispatch::TestProcess
,并使用 fixture_file_upload
> 帮手:
You need to include ActionDispatch::TestProcess
in your factory (Rails 3), and use the fixture_file_upload
helper:
include ActionDispatch::TestProcess
FactoryGirl.define do
factory :image do
title "Example image"
file { fixture_file_upload("files/example.jpg", "image/jpeg") }
end
end
另外一定要在test/fixtures/files/example.jpg
创建一个示例文件,否则你会得到文件不存在的错误.
Also be sure to create an example file at test/fixtures/files/example.jpg
, otherwise you will get an error that the file does not exist.
这篇关于带有载波上传字段的工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!