我在这里搜索了网站,但无法找到问题的解决方案。我有以下嵌套路线:
resources :posts, except: [:destroy] do
resources :comments, only: [:create]
end
我想测试评论控制器,特别是“创建”操作。
如果你要做rake:routes
,你会得到以下评论路线 - >创建:
/posts/:post_id/comments(.:format)
这就是参数哈希的样子:
=> {"utf8"=>"Γ£ô",
"authenticity_token"=>"1VTrTd9NrZ8t4l/p11xLlc1XJ/R1w9h6HTZVGaFkMxE=",
"comment"=>{"comment"=>"dafda"},
"commit"=>"Add Comment",
"action"=>"create",
"controller"=>"comments",
"post_id"=>"testing-the-formhfhgh"}
我不确定如何在RSpec测试中访问此路由。我尝试过以下方法:
post :create, post_id: post.slug, comment: { comment: "This is a comment" }
运行此命令会出现以下错误:
CommentsController POST create valid input displays a `flash[:notice]` message
←[31mFailure/Error:←[0m ←[31mpost :create, post_id: post.slug, comment: { comment: "This is a comment" }←[0m
←[31mArgumentError←[0m:
←[31mwrong number of arguments (2 for 0)←[0m
有人知道在这个控制器项上执行测试的正确语法是什么吗?