Rspec,回形针,制造,有效对象,无需保存到文件系统 [英] Rspec, Paperclip, Fabrication, valid object without saving to filesystem

查看:49
本文介绍了Rspec,回形针,制造,有效对象,无需保存到文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有回形针 3.2 的 rails 3.2 应用程序,我有一个带有所需回形针附件(拇指)的模型.如何在不将文件保存到文件系统或 S3 的情况下创建有效对象.我目前拥有的内容如下,但这会在每次运行时保存到文件系统中.有没有办法在不每次都上传的情况下获得有效的剧集?

I have a rails 3.2 app with paperclip 3.2 and I have a model that has a required paperclip attachment(thumb). How can I create valid objects without having the file saved to the filesystem or 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

推荐答案

发现这个:

http://room118solutions.com/2011/05/25/stubbing-paperclip-测试中/

对于回形针 3.0:Paperclip 3.0 中有一些重大变化,您现在应该使用以下内容:

for Paperclip 3.0: There were some significant changes in Paperclip 3.0, you should now use something like this:

spec/support/stub_paperclip_attachments.rb

spec/support/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

这篇关于Rspec,回形针,制造,有效对象,无需保存到文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆