I've searched the site here and was unable to find the solution to my issue. I have the following nested route:
resources :posts, except: [:destroy] do
resources :comments, only: [:create]
end
I'd like to test the comments controller, particularly the "create" action.
If you were to do a rake:routes
you'd get the following route for comments->create:
/posts/:post_id/comments(.:format)
This is what the parameters hash would look like:
=> {"utf8"=>"Γ£ô",
"authenticity_token"=>"1VTrTd9NrZ8t4l/p11xLlc1XJ/R1w9h6HTZVGaFkMxE=",
"comment"=>{"comment"=>"dafda"},
"commit"=>"Add Comment",
"action"=>"create",
"controller"=>"comments",
"post_id"=>"testing-the-formhfhgh"}
I'm not sure how I can access this route on an RSpec test. I have tried the following:
post :create, post_id: post.slug, comment: { comment: "This is a comment" }
Running this gives me the following error:
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
Does anybody know what the proper syntax for performing tests on this controller item?