I am trying to test the \'destroy\' action for my nested comments controller. Post has_many Comments
. I have ran into similar issues before and understand that I ne
The route that you want to request is this:
/posts/:post_id/comments/:id(.:format)
But you are sending the following parameters:
{:action=>"destroy", :comment=>"1", :controller=>"comments", :post_id=>"1"}
You need to send the comment.id
as the id
parameter.
Try this:
describe '#DELETE destroy' do
it 'deletes a comment' do
comment = create(:comment)
@post.comments << comment
# Also, test if the action really deletes a comment.
expect{delete :destroy, id: comment.id, post_id: @post}.
to change{@post.comments.count}.by(-1)
expect(response).to redirect_to post_path
end
end