diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-03-13 18:05:01 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-03-15 10:13:49 +0100 |
commit | 41a14dcd1045f61278237f34f065b87212689376 (patch) | |
tree | 0f7aafb34684d6ebf78e30b74f310a57b5a6fec1 /guides | |
parent | c1003d99b00b3afb5417b6853a3e2ba92638cbe8 (diff) | |
download | rails-41a14dcd1045f61278237f34f065b87212689376.tar.gz rails-41a14dcd1045f61278237f34f065b87212689376.tar.bz2 rails-41a14dcd1045f61278237f34f065b87212689376.zip |
`Http::Headers` directly modifies the passed environment.
The env hash passed to `Http::Headers#new` must be in env format.
Also be aware that the passed hash is modified directly.
docs and test-cases for setting headers/env in functional tests.
Follow up to #9700.
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/testing.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/guides/source/testing.md b/guides/source/testing.md index 40bf2603c4..1937cbf17a 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -501,6 +501,21 @@ You also have access to three instance variables in your functional tests: * `@request` - The request * `@response` - The response +### Setting Headers and CGI variables + +Headers and cgi variables can be set directly on the `@request` +instance variable: + +```ruby +# setting a HTTP Header +@request.headers["Accepts"] = "text/plain, text/html" +get :index # simulate the request with custom header + +# setting a CGI variable +@request.headers["HTTP_REFERER"] = "http://example.com/home" +post :create # simulate the request with custom env variable +``` + ### Testing Templates and Layouts If you want to make sure that the response rendered the correct template and layout, you can use the `assert_template` |