用回形针治具 [英] Fixtures with Paperclip

查看:97
本文介绍了用回形针治具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Paperclip来存储文档,但是我找不到如何创建它们的装置,我这样写:

I'm using Paperclip to store documents, but I can't find how to create fixtures of them, I wrote this :

<% doc = Document.create(:asset => File.open(Rails.root.join('spec', 'assets', 'image.png'))) %>
<%= part_event_image %>:
  asset_file_name: <%= doc.asset_file_name %>
  asset_content_type: <%= doc.asset_content_type %>
  asset_file_size: <%= doc.asset_file_size %>
  asset_updated_at: <%= doc.asset_updated_at %>
  documentable: party (Event) %>
<% end %>

但是我运行了一个文档,该文档存在于数据库中,但是没有存储.

But one I ran it, the document exist in the database, but it's not stored.

我应该自己存储文档(写文件)吗?还是有其他方法?

Should I store the document myself (write the file) ? Or is there an other way ?

推荐答案

您可以使用fixture_file_upload

include ActionDispatch::TestProcess
Document.create(:asset => fixture_file_upload("#{Rails.root}/path/to/image.png", "image/png"))

或与女工一起

include ActionDispatch::TestProcess

FactoryGirl.define do
  factory :asset do
    asset { fixture_file_upload("#{Rails.root}/path/to/image.png", "image/png") }
  end
end

这篇关于用回形针治具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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