在模型测试中,如何访问FIXTURE_FILE_UPLOAD?
fixture_file_upload
是集成测试中可用的助手。
在测试与活动存储的模型方法时,我需要访问此助手。我该怎么做?
fixture_file_upload
is a helper available in integration tests.
When testing a model method that deals with Active Storage, I need to get access to this helper. How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
,如API中所示是
rack :: test :: uploadedfile.new(file.join(actiondispatch :: intempatet.file_fixture_path,path,path),type)
的快捷方式。因此,您可以上传准备以这种方式进行测试的文件:
然后,您可以使用附加方法 contact并坚持 它:
或只是分配它,因此您可以测试诸如
tacteent> toctonment_changes < /代码>。例如,在
has_many
关系中:As seen in the API,
fixture_file_upload
is a shortcut forRack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.file_fixture_path, path), type)
.So you can upload a file ready to test this way:
You then can attach and persist it to the model using the attach method:
Or just assigning it, so you can test things like
attachment_changes
. For example, in ahas_many
relationship: