Testing Rails 5集成测试将夹具文件上传转换为字符串
EnvTesting Rails 5集成测试将夹具文件上传转换为字符串,testing,ruby-on-rails-5,Testing,Ruby On Rails 5,Env 轨道:5.1.3 Ruby:2.3.1p112 上下文 我有一个基本的集成测试,如下所示: class MerchandisesControllerTest < ActionDispatch::IntegrationTest def test_successful_create post org_merchandises_path(org, merchandise: merchandise_params) ... end def merchandis
轨道:5.1.3
Ruby:2.3.1p112 上下文
我有一个基本的集成测试,如下所示:
class MerchandisesControllerTest < ActionDispatch::IntegrationTest
def test_successful_create
post org_merchandises_path(org, merchandise: merchandise_params)
...
end
def merchandise_params
{
description: 'Get swole fast.',
name: 'Foo Powder',
price: 50,
images_attributes: {
'0' => {
image: fixture_file_upload('files/image.png', 'image/png'),
primary: true,
}
}
}
end
end
可能的相关问题由于某些原因,以以下方式使用post方法无法正确序列化/反序列化图像参数:
# Fails to properly serialize file param
post org_merchandises_path(org, merchandise: merchandise_params)
你必须这样做:
# Properly serializes the file param
post org_merchandises_path(org), params: { merchandise: merchandise_params }
我不知道为什么。看起来它应该是双向的,但事实并非如此
# Properly serializes the file param
post org_merchandises_path(org), params: { merchandise: merchandise_params }