javascript - 在测试期间收到 ArgumentError,但在开发中没有,为什么?
问题描述
更新:更新操作现在正在作为 JS 处理(感谢选项“xhr:true”),但是错误消息仍然存在......我不知道为什么它在测试期间抛出错误,但不是在运行时发展。
我更新了问题的标题和内容以反映这些变化。
所以现在我很茫然是什么可能导致这个错误......有什么想法吗?
每当我尝试测试控制器的更新操作时,我都会收到以下错误消息:
ArgumentError: wrong number of arguments (given 2, expected 0)
这是控制器中收到错误的位置:
def update
...
# \/ This line causing the error \/
if @image.update(image_params.except(:image_tags_attributes))
if image_params[:crop_x].present?
...
这是我正在运行的测试:
class ImagesControllerTest < ActionDispatch::IntegrationTest
# ....
test "should add current_user.id to tag related through table after an update action that contains crop parameters" do
log_in_as(@user)
patch image_path(@image), params: { image: {
crop_x: 100,
crop_y: 100,
crop_w: 100,
crop_h: 100,
crop_rotation_angle: 0,
image_tags_attributes: {
tag_title_attributes: {
title: @tag_title.title
},
tag_content_attributes: {
content: ""
}
}
}
}, xhr: true
assert ImageTagTitle.last.user_id == @user.id
end
end
据我所知,我以与开发方面相同的方式将所有内容传递给测试,所以我很困惑可能导致它们处理方式不同的原因。
提前感谢您提供的任何帮助和见解!
测试日志
Processing by ImagesController#update as JS
Parameters: {"image"=>{"crop_x"=>"100", "crop_y"=>"100", "crop_w"=>"100", "crop_h"=>"100", "crop_rotation_angle"=>"0", "image_tags_attributes"=>{"tag_title_attributes"=>{"title"=>"MyTitle1"}, "tag_content_attributes"=>{"content"=>""}}}, "id"=>"249799255"}
开发日志
Processing by ImagesController#update as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"IUXYLsxSoD/OYdnm5TH/3jNbaG+7bkwZJL39p/vePkEXrnNk3J+1nrFkgIT3rsQeFmzRdt5kRMO+Vpjo7F5BCg==", "image"=>{"image_tags_attributes"=>{"tag_title_attributes"=>{"title"=>"page number"}, "tag_content_attributes"=>{"content"=>""}}, "crop_x"=>"42.73287586330139", "crop_y"=>"45.58570767432143", "crop_w"=>"123.71134020618558", "crop_h"=>"117.08396046432024", "crop_rotation_angle"=>"0"}, "button"=>"", "id"=>"2"}
解决方案
推荐阅读
- java - 多模块gradle项目:无法调用其他模块方法
- python - 访问 JSON 字典中的嵌套数组
- excel - 在 Excel 中的每一行之后创建一个 for 循环以填充月份
- python - Discord bot 中有关添加角色的命令不起作用
- c++ - C ++ for循环迭代更改整数向量值
- java - 尝试将数组列表与方法和构造函数一起使用。这可以优化吗?
- nltk - 用于非英语语言的基于 Python 的标记器
- java - Java 9+ 项目可以在 Java 8 中使用单独的源模块吗?
- c++ - 有没有办法在运行时分析 MPI 应用程序?- 在运行时使用 MPI 调用所花费的时间
- python - 如何执行代数,例如 apple + apple = 2 apple?