aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/testing.md
diff options
context:
space:
mode:
authorPrathamesh Sonpatki <csonpatki@gmail.com>2016-06-20 22:44:03 +0800
committerPrathamesh Sonpatki <csonpatki@gmail.com>2016-06-21 12:05:38 +0800
commit16283e795111038d3effc189df634f938422c9ca (patch)
tree21a5bec8edc5e9f42aa5262b03132a31a2206d1f /guides/source/testing.md
parent0c998a14c45430afe85188f8ad13a696b077ffd9 (diff)
downloadrails-16283e795111038d3effc189df634f938422c9ca.tar.gz
rails-16283e795111038d3effc189df634f938422c9ca.tar.bz2
rails-16283e795111038d3effc189df634f938422c9ca.zip
Fix the docs for supported keyword args for Rails 5 style integration controller tests [ci skip]
- Fixes #25394.
Diffstat (limited to 'guides/source/testing.md')
-rw-r--r--guides/source/testing.md18
1 files changed, 11 insertions, 7 deletions
diff --git a/guides/source/testing.md b/guides/source/testing.md
index 050bdda9e3..924a8a09f5 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -695,7 +695,7 @@ end
In the `test_should_get_index` test, Rails simulates a request on the action called `index`, making sure the request was successful
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 accepts 4 arguments:
+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`).
@@ -703,22 +703,26 @@ The `get` method kicks off the web request and populates the results into the `@
* `params`: option with a hash of request parameters to pass into the action
(e.g. query string parameters or article variables).
-* `session`: option with a hash of session variables to pass along with the request.
+* `headers`: for setting the headers that will be passed with the request.
-* `flash`: option with a hash of flash values.
+* `env`: for customizing the request environment as needed.
+
+* `xhr`: whether the request is Ajax request or not. Can be set to true for marking the request as Ajax.
+
+* `as`: for encoding the request with different content type. Supports `:json` by default.
All of these keyword arguments are optional.
-Example: Calling the `:show` action, passing an `id` of 12 as the `params` and setting a `user_id` of 5 in the session:
+Example: Calling the `:show` action, passing an `id` of 12 as the `params` and setting `HTTP_REFERER` header:
```ruby
-get(:show, params: { id: 12 }, session: { user_id: 5 })
+get :show, params: { id: 12 }, headers: { "HTTP_REFERER" => "http://example.com/home" }
```
-Another example: Calling the `:view` action, passing an `id` of 12 as the `params`, this time with no session, but with a flash message.
+Another example: Calling the `:update` action, passing an `id` of 12 as the `params` as an Ajax request.
```ruby
-get(view_url, params: { id: 12 }, flash: { message: 'booya!' })
+get update_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.