シンプルなアプリの写真モデルをテストしているときに、非常に厄介なエラーが 1 つあります。
私の写真スペック
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