在rails 3中进行attachment_fu测试 [英] attachment_fu testing in rails 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 中很好地使用 fixture_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 3中进行attachment_fu测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!