在测试我的简单应用程序的照片模型时,我遇到了一个非常令人讨厌的错误。
我的照片规格
describe Photo do
before { @photo = Photo.create!(image: "5513770961_a73024a244_z.jpg", wraper: true, to_slider: true) }
subject { @photo }
it {should respond_to(:image)}
it {should respond_to(:wraper)}
it {should respond_to(:to_slider)}
it {should be_valid}
end
当这个规范执行时,它返回一个奇怪的错误
Failure/Error: before { @photo = Photo.create!(image: "5513770961_a73024a244_z.jpg", wraper: true, to_slider: true) }
ActiveRecord::RecordInvalid:
Validation failed: Image can't be blank
我的测试数据库已准备好并已加载,不要简单地弄清楚这一点...感谢您的帮助..)
照片模型:
class Photo < ActiveRecord::Base
attr_accessible :image, :gallery_id, :wraper, :to_slider
belongs_to :gallery
validates :image, presence: true
mount_uploader :image, ImageUploader
end