Class: ActionDispatch::Integration::Session
- Inherits:
-
Object
- Object
- ActionDispatch::Integration::Session
- Includes:
- Assertions, RequestHelpers, Routing::UrlFor, TestProcess, Minitest::Assertions
- Defined in:
- lib/action_dispatch/testing/integration.rb
Overview
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 IntegrationTest#open_session, rather than instantiating Integration::Session directly.
Constant Summary collapse
- DEFAULT_HOST =
"www.example.com"
Instance Attribute Summary collapse
-
#accept ⇒ Object
The Accept header to send.
-
#controller ⇒ Object
readonly
A reference to the controller instance used by the last request.
-
#host ⇒ Object
The hostname used in the last request.
-
#remote_addr ⇒ Object
The remote_addr used in the last request.
-
#request ⇒ Object
readonly
A reference to the request instance used by the last request.
-
#request_count ⇒ Object
A running counter of the number of requests processed.
-
#response ⇒ Object
readonly
A reference to the response instance used by the last request.
Instance Method Summary collapse
-
#cookies ⇒ Object
A map of the cookies returned by the last response, and which will be sent with the next request.
-
#https!(flag = true) ⇒ Object
Specify whether or not the session should mimic a secure HTTPS request.
-
#https? ⇒ Boolean
Returns
true
if the session is mimicking a secure HTTPS request. -
#initialize(app) ⇒ Session
constructor
Create and initialize a new Session instance.
-
#reset! ⇒ Object
Resets the instance.
- #url_options ⇒ Object
Methods included from Routing::UrlFor
Methods included from Routing::PolymorphicRoutes
#polymorphic_path, #polymorphic_url
Methods included from ActionController::ModelNaming
#convert_to_model, #model_name_from_record_or_class
Methods included from TestProcess
#assigns, #fixture_file_upload, #flash, #redirect_to_url, #session
Methods included from RequestHelpers
#delete, #delete_via_redirect, #follow_redirect!, #get, #get_via_redirect, #head, #patch, #patch_via_redirect, #post, #post_via_redirect, #put, #put_via_redirect, #request_via_redirect, #xml_http_request
Methods included from Assertions
Methods included from Assertions::RoutingAssertions
#assert_generates, #assert_recognizes, #assert_routing, #method_missing, #with_routing
Methods included from Assertions::ResponseAssertions
#assert_redirected_to, #assert_response
Constructor Details
#initialize(app) ⇒ Session
Create and initialize a new Session instance.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/action_dispatch/testing/integration.rb', line 184 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) singleton_class.class_eval do include app.routes.url_helpers include app.routes.mounted_helpers end end reset! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActionDispatch::Assertions::RoutingAssertions
Instance Attribute Details
#accept ⇒ Object
The Accept header to send.
161 162 163 |
# File 'lib/action_dispatch/testing/integration.rb', line 161 def accept @accept end |
#controller ⇒ Object (readonly)
A reference to the controller instance used by the last request.
170 171 172 |
# File 'lib/action_dispatch/testing/integration.rb', line 170 def controller @controller end |
#host ⇒ Object
The hostname used in the last request.
152 153 154 |
# File 'lib/action_dispatch/testing/integration.rb', line 152 def host @host || DEFAULT_HOST end |
#remote_addr ⇒ Object
The remote_addr used in the last request.
158 159 160 |
# File 'lib/action_dispatch/testing/integration.rb', line 158 def remote_addr @remote_addr end |
#request ⇒ Object (readonly)
A reference to the request instance used by the last request.
173 174 175 |
# File 'lib/action_dispatch/testing/integration.rb', line 173 def request @request end |
#request_count ⇒ Object
A running counter of the number of requests processed.
179 180 181 |
# File 'lib/action_dispatch/testing/integration.rb', line 179 def request_count @request_count end |
#response ⇒ Object (readonly)
A reference to the response instance used by the last request.
176 177 178 |
# File 'lib/action_dispatch/testing/integration.rb', line 176 def response @response end |
Instance Method Details
#cookies ⇒ Object
A map of the cookies returned by the last response, and which will be sent with the next request.
165 166 167 |
# File 'lib/action_dispatch/testing/integration.rb', line 165 def _mock_session. end |
#https!(flag = true) ⇒ Object
Specify whether or not the session should mimic a secure HTTPS request.
session.https!
session.https!(false)
241 242 243 |
# File 'lib/action_dispatch/testing/integration.rb', line 241 def https!(flag = true) @https = flag end |
#https? ⇒ Boolean
Returns true
if the session is mimicking a secure HTTPS request.
if session.https?
...
end
250 251 252 |
# File 'lib/action_dispatch/testing/integration.rb', line 250 def https? @https end |
#reset! ⇒ Object
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!
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/action_dispatch/testing/integration.rb', line 217 def reset! @https = false @controller = @request = @response = nil @_mock_session = nil @request_count = 0 @url_options = nil 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 # the helpers are made protected by default--we make them public for # easier access during testing and troubleshooting. @named_routes_configured = true end end |
#url_options ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/action_dispatch/testing/integration.rb', line 200 def @url_options ||= .dup.tap do || .reverse_merge!(controller.) if controller if @app.respond_to?(:routes) .reverse_merge!(@app.routes.) end .reverse_merge!(:host => host, :protocol => https? ? "https" : "http") end end |