From 41a14dcd1045f61278237f34f065b87212689376 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 13 Mar 2013 18:05:01 +0100 Subject: `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. --- guides/source/testing.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'guides/source/testing.md') 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` -- cgit v1.2.3