Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs for allowed params to get in controller tests [ci skip] #26605

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions guides/source/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,8 @@ and also ensuring that the right response body has been generated.

The `get` method kicks off the web request and populates the results into the `@response`. It can accept up to 6 arguments:

* The action of the controller you are requesting.
This can be in the form of a string or a route (i.e. `articles_url`).
* The URI of the controller action you are requesting.
This can be in the form of a string or a route helper (e.g. `articles_url`).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW this comment was useful, we should add it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I wanted to remove reference to string vs route, because I thought it was a little confusing. Isn't articles_url a method that returns a string?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

articles_url returns a string but /articles works as well :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can say route helper instead of just route to make it more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

* `params`: option with a hash of request parameters to pass into the action
(e.g. query string parameters or article variables).
* `headers`: for setting the headers that will be passed with the request.
Expand All @@ -775,13 +775,13 @@ All of these keyword arguments are optional.
Example: Calling the `:show` action, passing an `id` of 12 as the `params` and setting `HTTP_REFERER` header:

```ruby
get :show, params: { id: 12 }, headers: { "HTTP_REFERER" => "http://example.com/home" }
get article_url, params: { id: 12 }, headers: { "HTTP_REFERER" => "http://example.com/home" }
```

Another example: Calling the `:update` action, passing an `id` of 12 as the `params` as an Ajax request.

```ruby
patch update_url, params: { id: 12 }, xhr: true
patch article_url, params: { id: 12 }, xhr: true
```

NOTE: If you try running `test_should_create_article` test from `articles_controller_test.rb` it will fail on account of the newly added model level validation and rightly so.
Expand Down