来自该部分的following excerpt:
test "should redirect destroy for wrong micropost" do
log_in_as(users(:michael))
micropost = microposts(:ants)
assert_no_difference 'Micropost.count' do
delete micropost_path(micropost)
end
assert_redirected_to root_url
end
以下一行
delete micropost_path(micropost)
给了我以下错误:
ActionController::UrlGenerationError: No route matches
{:action=>"/microposts/583546149", :controller=>"microposts"}
比较动作:部分与我在网上看到的典型删除http请求的片段让我觉得有些本质上是错误的。我也好奇地注意到,在教程中,Michael Hartl通常使用以下语法来删除资源:
delete :destroy, id: micropost
为了清楚起见,后者似乎按预期工作。那么,我的问题是双重的:
两者都应该有效吗?有什么区别?
答案 0 :(得分:0)
该测试是为了确保无法创建微博(蚂蚁),因为该方法是微博(:橙子)。这就是它给出错误并重定向的原因,这就是它应该做的事情。所以测试通过了。
测试语法可能有所不同。