[英]I get No route matches [DELETE] "/" when testing click on delete link with capybara, works outside of system test
这是我的删除链接:
<%= link_to "delete", client, data: {
"turbo-method": :delete,
"turbo-confirm": "Are you sure?" } %>
这是使用 Minitest / Capybara / Selenium / Rails 7 的系统测试:
test "delete client" do
accept_confirm do
first("ul.clients li#client-#{@client.id} span.client-controls a").click
end
assert_selector "div.alert-success", text: "Client is deleted!"
end
当我运行测试时,我得到ActionController::RoutingError: No route matches [DELETE] "/"
当我尝试时:
puts first("ul.clients li#client-#{@client.id} span.client-controls a")["href"]
我得到了正确的 url (/clients/123)。 我读到了Capybara不接受turbo方法的这个问题,但它应该已经解决了: https://github.com/teamcapybara/capybara/commit/cc451e77b2fb6588e1d00814d0361e63bb66b86c
我正在使用 Rails 7、capybara (3.37.1)、selenium-webdriver (4.1.0)、minitest (5.15.0)
编辑以获取更多信息:刚刚检查了 test.log:
Started DELETE "/clients/298486374" for 127.0.0.1 at 2022-09-10 13:54:24 +0200
Processing by ClientsController#destroy as TURBO_STREAM
Parameters: {"id"=>"298486374"}
...删除查询是否可以正常工作...
Redirected to http://127.0.0.1:44597/
Completed 302 Found in 10ms (ActiveRecord: 1.2ms | Allocations: 1962)
Started DELETE "/" for 127.0.0.1 at 2022-09-10 13:54:25 +0200
为什么重定向后要求删除“/”????
我在 ClientsController 中的销毁操作:
def destroy
get_client.destroy
flash[:success] = "Client is deleted!"
redirect_to root_url
end
private
def get_client
Client.find(params[:id])
end
所以......是的......我想我在这里发布问题太快了......但是,对于其他有同样问题的人来说,这是解决方案:
我刚刚在我的销毁操作中的redirect_to root_url
status: :see_other
,现在它工作正常。
我从这篇旧帖子中得到了这个想法: https://makandracards.com/makandra/38347-redirecting-responses-for-patch-or-delete-will-not-redirect-with-get
如果有人想贡献,仍然不确定它为什么会这样工作 - 请做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.