How do you test the params hash in a Rails test?

The following error is generated: "undefined local variable or method" params ""

assert_equal params[:recipient_id], users(:one).id

How do you check the params hash?

Also, how do you test assert_redirect when parameters are present? Parameters are added to the URL, so testing for model_path or similar crashes.

Working with the built-in test class in Rails 3.

+7
source share
1 answer

http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers provides some of this information.

In this case, the parameters are attached to the @request or @response (depending on which HTTP method you are testing), so you can refer to it as @request.params[:recipient_id] .

For redirection: assert_redirected_to post_path(assigns(:post)) will state that you are redirected to the correct path for this model. The assigns method must have instance variables that you set inside the controller to go to the view

+7
source

All Articles