0

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?

zishe
  • 10,665
  • 12
  • 64
  • 103
DMiller
  • 253
  • 1
  • 3
  • 15
  • maybe `post.slug` thinks its the post method. try renaming your post object just to make sure there is not a name collision. – Jed Schneider Dec 12 '13 at 13:41
  • I can see a `wrong number of arguments (2 for 0) error`. Could you also post your create action and the full stack trace of the error? – usha Dec 12 '13 at 14:51
  • Vimsha, the code actually works ok, its the test that I can't seem to get tto pass. Do you still want to take a look at the create action? – DMiller Dec 12 '13 at 15:01

0 Answers0