3

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

模型:

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
4

1 回答 1

6

发现这个:

http://room118solutions.com/2011/05/25/stubbing-paperclip-during-testing/

对于 Paperclip 3.0:Paperclip 3.0 发生了一些重大变化,您现在应该使用如下内容:

规范/支持/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
于 2012-11-26T12:02:36.200 回答