[英]Rspec, Paperclip, Fabrication, valid object without saving to filesystem
I have a rails 3.2 app with paperclip 3.2 and I have a model that has a required paperclip attachment(thumb). 我有一个带有paperclip 3.2的rails 3.2应用程序,我有一个带有所需回形针附件(拇指)的模型。 How can I create valid objects without having the file saved to the filesystem or S3.
如何在不将文件保存到文件系统或S3的情况下创建有效对象。 What I currently have is below but this saves to the filesystem on each run.
我目前拥有的是下面的内容,但每次运行时都会保存到文件系统中。 Is there a way to have a valid episode without uploading everytime?
有没有办法在没有每次上传的情况下拥有有效的剧集?
class Episode
include Mongoid::Document
include Mongoid::Paperclip
has_mongoid_attached_file :thumb
validates_attachment_presence :thumb
end
require 'spec_helper'
describe Episode do
it "has a valid factory" do
Fabricate.build(:episode).should be_valid
end
end
Fabricator(:episode) do
thumb { File.open(File.join(Rails.root, 'spec', 'fabricators', 'assets', 'thumb.jpg'))}
end
Found this: 发现这个:
http://room118solutions.com/2011/05/25/stubbing-paperclip-during-testing/ http://room118solutions.com/2011/05/25/stubbing-paperclip-during-testing/
for Paperclip 3.0: There were some significant changes in Paperclip 3.0, you should now use something like this: 对于Paperclip 3.0:Paperclip 3.0有一些重大变化,你现在应该使用这样的东西:
spec/support/stub_paperclip_attachments.rb 规格/支持/ stub_paperclip_attachments.rb
module Paperclip
class Attachment
def save
@queued_for_delete = []
@queued_for_write = {}
true
end
private
def post_process
true
end
end
# This is only necessary if you're validating the content-type
class ContentTypeDetector
private
def empty?
false
end
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.