这是我的模特儿工厂
factory :photo do
user
image Rack::Test::UploadedFile.new(File.join(Rails.root,'spec','GIV_jpg_file_small.jpg'))
end
这是照片模型,其中图像是列的名称。我正在使用回形针宝石拍摄图像。
class Photo < ActiveRecord::Base
has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment :image, :presence => true
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
validates_attachment_size :image, :less_than => 1.megabytes
belongs_to :user
end
现在,当我为此照片模型运行Rspec时,它显示
Failure/Error: let(:photo) {FactoryGirl.create(:photo)}
ActiveRecord::RecordInvalid:
Validation failed: Image content type is invalid, Image is invalid
有人可以解决我的问题吗?提前致谢。
您缺少的第二个参数Rack::Test::UploadedFile.new
。它需要知道content_type。只需添加“图像/ jpg”即可:
image_path = File.join(Rails.root,'spec','GIV_jpg_file_small.jpg')
Rack::Test::UploadedFile.new image_path, 'image/jpg'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句