validates_attachment_presence
所以现在我用规范中的这些属性创建我的模型来尝试关闭它:
@attr = { :name => "value for name", :title => "value for title", :content => "value for content", :pic_file_name => "example.jpg", :pic_content_type => "image/jpg", :pic_file_size => "8192", :pic_updated_at => nil }
不过,这行不通。
我发现这个: http://fr.ivolo.us/posts/mocking-paperclip-with-rspec 所以我试着这样做:
Post.should_receive(:save_attached_files).and_return(true)
这也不管用。我怎么安抚RSpec?
如果模型 has_attached_file :pic ,你应该能指出 pic 属性在某个文件和所有应该是花花公子。
has_attached_file :pic
pic
@attr = { :pic => File.open(File.join(Rails.root, 'spec', 'fixtures', 'file.png')) }