An integration Session instance represents a set of requests and responses performed sequentially by some virtual user. Because 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
Included Modules
Classes and Modules
Class ActionController::Integration::Session::MultiPartNeededException
Attributes
[RW] accept The Accept header to send.
[RW] application Rack application to use
[R] body The body of the last request.
[R] controller A reference to the controller instance used by the last request.
[R] cookies A map of the cookies returned by the last response, and which will be sent with the next request.
[R] headers A map of the headers returned by the last response.
[RW] host The hostname used in the last request.
[R] path The URI of the last request.
[RW] remote_addr The remote_addr used in the last request.
[R] request A reference to the request instance used by the last request.
[RW] request_count A running counter of the number of requests processed.
[R] response A reference to the response instance used by the last request.
[R] status The integer HTTP status code of the last request.
[R] status_message The status message that accompanied the status code of the last request.
Public Class methods
new(app = nil)

Create and initialize a new Session instance.

    # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 67
67:       def initialize(app = nil)
68:         @application = app || ActionController::Dispatcher.new
69:         reset!
70:       end
Public Instance methods
delete(path, parameters = nil, headers = nil)

Performs a DELETE request with the given parameters. See get() for more details.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 213
213:       def delete(path, parameters = nil, headers = nil)
214:         process :delete, path, parameters, headers
215:       end
delete_via_redirect(path, parameters = nil, headers = nil)

Performs a DELETE request, following any subsequent redirect. See request_via_redirect for more information.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 166
166:       def delete_via_redirect(path, parameters = nil, headers = nil)
167:         request_via_redirect(:delete, path, parameters, headers)
168:       end
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.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 130
130:       def follow_redirect!
131:         raise "not a redirect! #{@status} #{@status_message}" unless redirect?
132:         get(interpret_uri(headers['location']))
133:         status
134:       end
get(path, parameters = nil, headers = nil)

Performs a GET request with the given parameters.

  • path: The URI (as a String) on which you want to perform a GET request.
  • parameters: The HTTP parameters that you want to pass. This may be nil, a Hash, or a String that is appropriately encoded (application/x-www-form-urlencoded or multipart/form-data).
  • headers: Additional HTTP headers to pass, as a Hash. The keys will automatically be upcased, with the prefix ‘HTTP_’ added if needed.

This method returns an Response object, which one can use to inspect the details of the response. Furthermore, if this method was called from an ActionController::IntegrationTest object, then that object‘s @response instance variable will point to the same response object.

You can also perform POST, PUT, DELETE, and HEAD requests with post, put, delete, and head.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 195
195:       def get(path, parameters = nil, headers = nil)
196:         process :get, path, parameters, headers
197:       end
get_via_redirect(path, parameters = nil, headers = nil)

Performs a GET request, following any subsequent redirect. See request_via_redirect for more information.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 148
148:       def get_via_redirect(path, parameters = nil, headers = nil)
149:         request_via_redirect(:get, path, parameters, headers)
150:       end
head(path, parameters = nil, headers = nil)

Performs a HEAD request with the given parameters. See get() for more details.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 219
219:       def head(path, parameters = nil, headers = nil)
220:         process :head, path, parameters, headers
221:       end
host!(name)

Set the host name to use in the next request.

  session.host! "www.example.com"
     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 123
123:       def host!(name)
124:         @host = name
125:       end
https!(flag = true)

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

  session.https!
  session.https!(false)
     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 107
107:       def https!(flag = true)
108:         @https = flag
109:       end
https?()

Return true if the session is mimicking a secure HTTPS request.

  if session.https?
    ...
  end
     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 116
116:       def https?
117:         @https
118:       end
post(path, parameters = nil, headers = nil)

Performs a POST request with the given parameters. See get() for more details.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 201
201:       def post(path, parameters = nil, headers = nil)
202:         process :post, path, parameters, headers
203:       end
post_via_redirect(path, parameters = nil, headers = nil)

Performs a POST request, following any subsequent redirect. See request_via_redirect for more information.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 154
154:       def post_via_redirect(path, parameters = nil, headers = nil)
155:         request_via_redirect(:post, path, parameters, headers)
156:       end
put(path, parameters = nil, headers = nil)

Performs a PUT request with the given parameters. See get() for more details.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 207
207:       def put(path, parameters = nil, headers = nil)
208:         process :put, path, parameters, headers
209:       end
put_via_redirect(path, parameters = nil, headers = nil)

Performs a PUT request, following any subsequent redirect. See request_via_redirect for more information.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 160
160:       def put_via_redirect(path, parameters = nil, headers = nil)
161:         request_via_redirect(:put, path, parameters, headers)
162:       end
redirect?()

Returns true if the last response was a redirect.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 171
171:       def redirect?
172:         status/100 == 3
173:       end
request_via_redirect(http_method, path, parameters = nil, headers = nil)

Performs a request using the specified method, 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.

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 140
140:       def request_via_redirect(http_method, path, parameters = nil, headers = nil)
141:         send(http_method, path, parameters, headers)
142:         follow_redirect! while redirect?
143:         status
144:       end
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!
     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 77
 77:       def reset!
 78:         @status = @path = @headers = nil
 79:         @result = @status_message = nil
 80:         @https = false
 81:         @cookies = {}
 82:         @controller = @request = @response = nil
 83:         @request_count = 0
 84: 
 85:         self.host        = "www.example.com"
 86:         self.remote_addr = "127.0.0.1"
 87:         self.accept      = "text/xml,application/xml,application/xhtml+xml," +
 88:                            "text/html;q=0.9,text/plain;q=0.8,image/png," +
 89:                            "*/*;q=0.5"
 90: 
 91:         unless defined? @named_routes_configured
 92:           # install the named routes in this session instance.
 93:           klass = class << self; self; end
 94:           Routing::Routes.install_helpers(klass)
 95: 
 96:           # the helpers are made protected by default--we make them public for
 97:           # easier access during testing and troubleshooting.
 98:           klass.module_eval { public *Routing::Routes.named_routes.helpers }
 99:           @named_routes_configured = true
100:         end
101:       end
url_for(options)

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

     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 240
240:       def url_for(options)
241:         controller ?
242:           controller.url_for(options) :
243:           generic_url_rewriter.rewrite(options)
244:       end
xhr(request_method, path, parameters = nil, headers = nil)

Alias for xml_http_request

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

Performs an XMLHttpRequest request with the given parameters, mirroring a request from the Prototype library.

The request_method is :get, :post, :put, :delete or :head; the parameters are nil, a hash, or a url-encoded or multipart string; the headers are a hash. Keys are automatically upcased and prefixed with ‘HTTP_’ if not already.

This method is also aliased as xhr
     # File vendor/rails/actionpack/lib/action_controller/integration.rb, line 230
230:       def xml_http_request(request_method, path, parameters = nil, headers = nil)
231:         headers ||= {}
232:         headers['X-Requested-With'] = 'XMLHttpRequest'
233:         headers['Accept'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
234:         process(request_method, path, parameters, headers)
235:       end