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 ActionController::IntegrationTest#open_session, rather than instantiating Integration::Session directly.
- D
- F
- G
- H
- N
- P
- R
- U
- X
- Test::Unit::Assertions
- ActionController::Assertions
- ActionController::TestProcess
[RW] | accept | The Accept header to send. |
[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. |
[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. |
Create an initialize a new Session instance.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 55 def initialize reset! end
Performs a DELETE request with the given parameters. See get() for more details.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 166 def delete(path, parameters=nil, headers=nil) process :delete, path, parameters, headers end
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.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 114 def follow_redirect! raise "not a redirect! #{@status} #{@status_message}" unless redirect? get(interpret_uri(headers['location'].first)) status end
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.
You can also perform POST, PUT, DELETE, and HEAD requests with post, put, delete, and head.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 151 def get(path, parameters=nil, headers=nil) process :get, path, parameters, headers end
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.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 124 def get_via_redirect(path, args={}) get path, args follow_redirect! while redirect? status end
Performs a HEAD request with the given parameters. See get() for more details.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 171 def head(path, parameters=nil, headers=nil) process :head, path, parameters, headers end
Set the host name to use in the next request.
session.host! "www.example.com"
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 107 def host!(name) @host = name end
Specify whether or not the session should mimic a secure HTTPS request.
session.https! session.https!(false)
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 91 def https!(flag=true) @https = flag end
Return true
if the session is mimicing a secure HTTPS request.
if session.https? ... end
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 100 def https? @https end
Performs a POST request with the given parameters. See get() for more details.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 156 def post(path, parameters=nil, headers=nil) process :post, path, parameters, headers end
Performs a POST request, following any subsequent redirect. This is vulnerable to infinite loops, the same as get_via_redirect.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 132 def post_via_redirect(path, args={}) post path, args follow_redirect! while redirect? status end
Performs a PUT request with the given parameters. See get() for more details.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 161 def put(path, parameters=nil, headers=nil) process :put, path, parameters, headers end
Returns true
if the last response was a redirect.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 139 def redirect? status/100 == 3 end
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!
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 64 def reset! @status = @path = @headers = nil @result = @status_message = nil @https = false @cookies = {} @controller = @request = @response = nil self.host = "www.example.com" self.remote_addr = "127.0.0.1" self.accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" unless @named_routes_configured # install the named routes in this session instance. klass = class<<self; self; end Routing::Routes.named_routes.install(klass) # the helpers are made protected by default--we make them public for # easier access during testing and troubleshooting. klass.send(:public, *Routing::Routes.named_routes.helpers) @named_routes_configured = true end end
Returns the URL for the given options, according to the rules specified in the application’s routes.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 202 def url_for(options) controller ? controller.url_for(options) : generic_url_rewriter.rewrite(options) end
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 used to omit the request_method parameter, assuming it was :post. This was deprecated in Rails 1.2.4. Always pass the request method as the first argument.
Source: show
# File rails/actionpack/lib/action_controller/integration.rb, line 186 def xml_http_request(request_method, path, parameters = nil, headers = nil) unless request_method.is_a?(Symbol) ActiveSupport::Deprecation.warn 'xml_http_request now takes the request_method (:get, :post, etc.) as the first argument. It used to assume :post, so add the :post argument to your existing method calls to silence this warning.' request_method, path, parameters, headers = :post, request_method, path, parameters end headers ||= {} headers['X-Requested-With'] = 'XMLHttpRequest' headers['Accept'] = 'text/javascript, text/html, application/xml, text/xml, */*' process(request_method, path, parameters, headers) end