更新:现在,更新操作正在作为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
据我所知,我以与开发方面相同的方式将所有内容传递给测试,因此我很困惑可能导致它们处理方式不同的原因。
在此先感谢您提供的帮助和见解!
test.log
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"}
development.log
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"}