【发布时间】:2014-07-25 14:27:50
【问题描述】:
这是我的照片模型工厂
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
有人可以解决我的问题吗? 提前致谢。
【问题讨论】:
标签: ruby-on-rails-4 paperclip factory-bot