rails 3 中的attachment_fu 测试

发布于 2024-09-28 05:52:03 字数 271 浏览 6 评论 0原文

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

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

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浪漫之都 2024-10-05 05:52:03

我能够将fixture_file_upload 与Rails3 和rspec 一起使用。

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

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

编辑:我升级的内容更改了它的行为以始终包含固定装置路径,因此我切换到这个而不是fixture_file_upload:

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

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

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')

EDIT: 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')
爱给你人给你 2024-10-05 05:52:03

我现在正在测试 Rails 3 中的文件上传,尽管我不知道我的答案会有多大帮助。您可以更改测试吗?就我个人而言,我使用的是黄瓜/水豚方法。 Capybara 的 DSL 定义

attach_file('Image', '/path/to/image.jpg')

就个人而言,这似乎是比与 StringIO 对象交互更好的测试方法......随意反驳。

I'm working on testing file uploads in rails 3 right now, although I don't know how helpful my answer will be. Would it be possible for you to change the test? Personally, I'm using a Cucumber/Capybara approach. Capybara's DSL defines

attach_file('Image', '/path/to/image.jpg')

Personally this seems a better way to test than interacting with the StringIO object...feel free to retort.

嘿看小鸭子会跑 2024-10-05 05:52:03

对于 Rails 3 来说,找到这个有点棘手。

您仍然可以使用 fixture_file_upload 函数,但您必须添加:

include ActionDispatch::TestProcess

到您的测试用例中。

这对 Rspec 根本不起作用。我只需获取文件本身并直接发布文件即可。

This was somewhat tricky to find for Rails 3

You can still use the fixture_file_upload function, but you have to add:

include ActionDispatch::TestProcess

To your test case.

This didn't work at all with Rspec. I just had to grab the file itself and post the file directly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文