Class: ActionController::Integration::Session

Class | ActionController::Integration::Session
In: | lib/action_controller/integration.rb
Parent: | Object

An integration Session instance represents a set of requests and responses performed sequentially by some virtual user. Becase you can instantiate multiple sessions and run them side-by-side, you can also mimic (to some limited extent) multiple simultaneous users interacting with your system.

Typically, you will instantiate a new session using IntegrationTest#open_session, rather than instantiating Integration::Session directly.

### Methods

follow_redirect! get get_via_redirect host! https! https? new post post_via_redirect redirect? reset! url_for xml_http_request

### Included Modules

Test::Unit::Assertions ActionController::TestProcess

### Attributes

accept | [RW] | The Accept header to send.
controller | [R] | A reference to the controller instance used by the last request.
cookies | [R] | A map of the cookies returned by the last response, and which will be sent with the next request.
headers | [R] | A map of the headers returned by the last response.
host | [RW] | The hostname used in the last request.
path | [R] | The URI of the last request.
remote_addr | [RW] | The remote_addr used in the last request.
request | [R] | A reference to the request instance used by the last request.
response | [R] | A reference to the response instance used by the last request.
status | [R] | The integer HTTP status code of the last request.
status_message | [R] | The status message that accompanied the status code of the last request.

### Public Class methods

new()

Create an initialize a new Session instance.

### Public Instance methods

follow_redirect!()

Follow a single redirect response. If the last response was not a redirect, an exception will be raised. Otherwise, the redirect is performed on the location header.

get(path, parameters=nil, headers=nil)

Performs a GET request with the given parameters. The parameters may be `nil`, a Hash, or a string that is appropriately encoded (application/x-www-form-urlencoded or multipart/form-data). The headers should be a hash. The keys will automatically be upcased, with the prefix ‘HTTP_’ added if needed.

get_via_redirect(path, args={})

Performs a GET request, following any subsequent redirect. Note that the redirects are followed until the response is not a redirect—this means you may run into an infinite loop if your redirect loops back to itself.

host!(name)

Set the host name to use in the next request.

      session.host! "www.example.com"

https!(flag=true)

Specify whether or not the session should mimic a secure HTTPS request.

      session.https!
      session.https!(false)

https?()

Return `true` if the session is mimicing a secure HTTPS request.

      if session.https?
        ...
      end

post(path, parameters=nil, headers=nil)

Performs a POST request with the given parameters. The parameters may be `nil`, a Hash, or a string that is appropriately encoded (application/x-www-form-urlencoded or multipart/form-data). The headers should be a hash. The keys will automatically be upcased, with the prefix ‘HTTP_’ added if needed.

post_via_redirect(path, args={})

Performs a POST request, following any subsequent redirect. This is vulnerable to infinite loops, the same as get_via_redirect.

redirect?()

Returns `true` if the last response was a redirect.

reset!()

Resets the instance. This can be used to reset the state information in an existing session instance, so it can be used from a clean-slate condition.

      session.reset!

url_for(options)

Returns the URL for the given options, according to the rules specified in the application‘s routes.

xml_http_request(path, parameters=nil, headers=nil)

Performs an XMLHttpRequest request with the given parameters, mimicing the request environment created by the Prototype library. The parameters may be `nil`, a Hash, or a string that is appropriately encoded (application/x-www-form-urlencoded or multipart/form-data). The headers should be a hash. The keys will automatically be upcased, with the prefix ‘HTTP_’ added if needed.

[Validate]