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.
- delete
- follow_redirect!
- get
- get_via_redirect
- head
- host!
- https!
- https?
- new
- post
- post_via_redirect
- put
- redirect?
- reset!
- url_for
- xml_http_request
- 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. |
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 55
55: def initialize
56: reset!
57: end
Performs a DELETE request with the given parameters. See get() for more details.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 166
166: def delete(path, parameters=nil, headers=nil)
167: process :delete, path, parameters, headers
168: 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.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 114
114: def follow_redirect!
115: raise "not a redirect! #{@status} #{@status_message}" unless redirect?
116: get(interpret_uri(headers['location'].first))
117: status
118: 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.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 151
151: def get(path, parameters=nil, headers=nil)
152: process :get, path, parameters, headers
153: 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.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 124
124: def get_via_redirect(path, args={})
125: get path, args
126: follow_redirect! while redirect?
127: status
128: end
Performs a HEAD request with the given parameters. See get() for more details.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 171
171: def head(path, parameters=nil, headers=nil)
172: process :head, path, parameters, headers
173: end
Set the host name to use in the next request.
session.host! "www.example.com"
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 107
107: def host!(name)
108: @host = name
109: end
Specify whether or not the session should mimic a secure HTTPS request.
session.https! session.https!(false)
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 91
91: def https!(flag=true)
92: @https = flag
93: end
Return true if the session is mimicing a secure HTTPS request.
if session.https?
...
end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 100
100: def https?
101: @https
102: end
Performs a POST request with the given parameters. See get() for more details.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 156
156: def post(path, parameters=nil, headers=nil)
157: process :post, path, parameters, headers
158: end
Performs a POST request, following any subsequent redirect. This is vulnerable to infinite loops, the same as get_via_redirect.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 132
132: def post_via_redirect(path, args={})
133: post path, args
134: follow_redirect! while redirect?
135: status
136: end
Performs a PUT request with the given parameters. See get() for more details.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 161
161: def put(path, parameters=nil, headers=nil)
162: process :put, path, parameters, headers
163: end
Returns true if the last response was a redirect.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 139
139: def redirect?
140: status/100 == 3
141: 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!
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 64
64: def reset!
65: @status = @path = @headers = nil
66: @result = @status_message = nil
67: @https = false
68: @cookies = {}
69: @controller = @request = @response = nil
70:
71: self.host = "www.example.com"
72: self.remote_addr = "127.0.0.1"
73: self.accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
74:
75: unless @named_routes_configured
76: # install the named routes in this session instance.
77: klass = class<<self; self; end
78: Routing::Routes.named_routes.install(klass)
79:
80: # the helpers are made protected by default--we make them public for
81: # easier access during testing and troubleshooting.
82: klass.send(:public, *Routing::Routes.named_routes.helpers)
83: @named_routes_configured = true
84: end
85: end
Returns the URL for the given options, according to the rules specified in the application‘s routes.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 192
192: def url_for(options)
193: controller ? controller.url_for(options) : generic_url_rewriter.rewrite(options)
194: end
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.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/integration.rb, line 181
181: def xml_http_request(path, parameters=nil, headers=nil)
182: headers = (headers || {}).merge(
183: "X-Requested-With" => "XMLHttpRequest",
184: "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
185: )
186:
187: post(path, parameters, headers)
188: end