在rails中的attachment_fu测试3 [英] attachment_fu testing in rails 3

查看:101
本文介绍了在rails中的attachment_fu测试3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用attachment_fu为工作文件上传功能编写规范.但是,作者提供的用于测试的示例代码要求我要求action_controller/test_process,以便我可以访问ActionController::UploadedStringIO类.我以前在rails 2.x中使用过此功能,但对于rails 3,它无法找到test_process文件.

I am trying to write specs for a working file upload functionality using attachment_fu. However, the sample code given by the author for testing requires me to require action_controller/test_process so that I have access to ActionController::UploadedStringIO class. I have used this before in rails 2.x but for rails 3, it fails to locate the test_process file.

如何继续测试Rails 3中的文件上传功能?

How do I go ahead with testing the file upload functionality in rails 3?

推荐答案

我能够与Rails3和rspec一起使用fix_file_upload.

I was able to use fixture_file_upload just fine with Rails3 and rspec.

我刚刚将include ActionDispatch::TestProcess添加到spec_helper.rb,然后将如下内容作为文件数据传递:

I just added include ActionDispatch::TestProcess to the spec_helper.rb, and then passed something like the following as the filedata:

fixture_file_upload(Rails.root.join("spec/support/test.png"), 'image/png')

我进行了一些升级,将其行为更改为始终包含灯具路径,因此我切换到了该灯具,而不是fixture_file_upload:

Something I upgraded changed the behavior of this to always include the fixtures path, so I switched to this instead of fixture_file_upload:

Rack::Test::UploadedFile.new(Rails.root.join("spec/support/test.png"), 'image/png')

这篇关于在rails中的attachment_fu测试3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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