An instance of this class represents a set of requests and responses performed sequentially by a test process. 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 ActionDispatch::Integration::Runner#open_session, rather than instantiating Integration::Session directly.
- Test::Unit::Assertions
- ActionDispatch::TestProcess
- ActionDispatch::Integration::RequestHelpers
- ActionDispatch::Assertions
- ActionDispatch::Routing::UrlFor
- ActionController::Testing
DEFAULT_HOST | = | "www.example.com" |
[RW] | accept | The Accept header to send. |
[R] | controller | A reference to the controller instance used by the last request. |
[W] | host | |
[W] | host! | |
[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. |
Create and initialize a new Session instance.
Source: show
# File actionpack/lib/action_dispatch/testing/integration.rb, line 174 def initialize(app) super() @app = app # If the app is a Rails app, make url_helpers available on the session # This makes app.url_for and app.foo_path available in the console if app.respond_to?(:routes) && app.routes.respond_to?(:url_helpers) singleton_class.class_eval { include app.routes.url_helpers } end reset! end
A map of the cookies returned by the last response, and which will be sent with the next request.
Source: show
Source: show
# File actionpack/lib/action_dispatch/testing/integration.rb, line 188 def default_url_options { :host => host, :protocol => https? ? "https" : "http" } end
The hostname used in the last request.
Source: show
# File actionpack/lib/action_dispatch/testing/integration.rb, line 142 def host @host || DEFAULT_HOST end
Specify whether or not the session should mimic a secure HTTPS request.
session.https! session.https!(false)
Source: show
# File actionpack/lib/action_dispatch/testing/integration.rb, line 223 def https!(flag = true) @https = flag end
Return true
if the session is mimicking a secure HTTPS
request.
if session.https? ... end
Source: show
# File actionpack/lib/action_dispatch/testing/integration.rb, line 232 def https? @https 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 actionpack/lib/action_dispatch/testing/integration.rb, line 197 def reset! @https = false @controller = @request = @response = nil @_mock_session = nil @request_count = 0 self.host = DEFAULT_HOST 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 defined? @named_routes_configured # install the named routes in this session instance. klass = singleton_class # the helpers are made protected by default--we make them public for # easier access during testing and troubleshooting. @named_routes_configured = true end end