0

在测试我的简单应用程序的照片模型时,我遇到了一个非常令人讨厌的错误。

我的照片规格

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
4

1 回答 1

0

please just don't give the image name give the the full path like

make image attribute accessible

by adding this line to the model

attr_accessible :image

example: ---

before { @photo = Photo.create!(image: "#{Rails.root}/spec/images/5513770961_a73024a244_z.jpg", wraper: true, to_slider: true) }
于 2013-07-03T06:36:14.470 回答