Class: ActionDispatch::Integration::Session
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Instance Chain: 
          self,
          ::ActionDispatch::Routing::UrlFor,
          ::ActionDispatch::Routing::PolymorphicRoutes,
          ::ActionController::ModelNaming,
          ::ActionDispatch::TestProcess,
          RequestHelpers,
          ::ActionDispatch::Assertions,
          Rails::Dom::Testing::Assertions,
          ::ActionDispatch::Assertions::RoutingAssertions,
          ::ActionDispatch::Assertions::ResponseAssertions,
          Minitest::Assertions
         | |
| Inherits: | Object | 
| Defined in: | actionpack/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 Session directly.
Constant Summary
- 
    DEFAULT_HOST =
    
 # File 'actionpack/lib/action_dispatch/testing/integration.rb', line 138"www.example.com"
::ActionDispatch::Routing::UrlFor - Attributes & Methods
Class Method Summary
- 
    
      .new(app)  ⇒ Session 
    
    constructor
    Create and initialize a new Sessioninstance.
Instance Attribute Summary
- 
    
      #accept  
    
    rw
    The Accept header to send. 
- 
    
      #controller  
    
    readonly
    A reference to the controller instance used by the last request. 
- 
    
      #host  
    
    rw
    The hostname used in the last request. 
- #host=(value) (also: #host!) rw
- 
    
      #https?  ⇒ Boolean 
    
    readonly
    Returns trueif the session is mimicking a secure HTTPS request.
- 
    
      #remote_addr  
    
    rw
    The remote_addr used in the last request. 
- 
    
      #request  
    
    readonly
    A reference to the request instance used by the last request. 
- 
    
      #request_count  
    
    rw
    A running counter of the number of requests processed. 
- 
    
      #response  
    
    readonly
    A reference to the response instance used by the last request. 
Instance Method Summary
- 
    
      #cookies  
    
    A map of the cookies returned by the last response, and which will be sent with the next request. 
- 
    
      #https!(flag = true)  
    
    Specify whether or not the session should mimic a secure HTTPS request. 
- 
    
      #reset!  
    
    Resets the instance. 
- #url_options
::ActionDispatch::Routing::UrlFor - Included
| #initialize, | |
| #url_for | Generate a url based on the options provided, default_url_options and the routes defined in routes.rb. | 
| #url_options | Hook overridden in controller to add request information with .default_url_options. | 
::ActionDispatch::Routing::PolymorphicRoutes - Included
| #polymorphic_path | Returns the path component of a URL for the given record. | 
| #polymorphic_url | Constructs a call to a named RESTful route for the given record and returns the resulting URL string. | 
::ActionController::ModelNaming - Included
| #convert_to_model | Converts the given object to an ::ActiveModel compliant one. | 
| #model_name_from_record_or_class | |
::ActionDispatch::TestProcess - Included
| #assigns, #cookies, | |
| #fixture_file_upload | Shortcut for  | 
| #flash, #redirect_to_url, #session | |
RequestHelpers - Included
| #delete | Performs a DELETE request with the given parameters. | 
| #delete_via_redirect | Performs a DELETE request, following any subsequent redirect. | 
| #follow_redirect! | Follow a single redirect response. | 
| #get | Performs a GET request with the given parameters. | 
| #get_via_redirect | Performs a GET request, following any subsequent redirect. | 
| #head | Performs a HEAD request with the given parameters. | 
| #patch | Performs a PATCH request with the given parameters. | 
| #patch_via_redirect | Performs a PATCH request, following any subsequent redirect. | 
| #post | Performs a POST request with the given parameters. | 
| #post_via_redirect | Performs a POST request, following any subsequent redirect. | 
| #put | Performs a PUT request with the given parameters. | 
| #put_via_redirect | Performs a PUT request, following any subsequent redirect. | 
| #request_via_redirect | Performs a request using the specified method, following any subsequent redirect. | 
| #xhr | Alias for RequestHelpers#xml_http_request. | 
| #xml_http_request | Performs an XMLHttpRequest request with the given parameters, mirroring a request from the Prototype library. | 
::ActionDispatch::Assertions - Included
::ActionDispatch::Assertions::RoutingAssertions - Included
| #assert_generates | Asserts that the provided options can be used to generate the provided path. | 
| #assert_recognizes | Asserts that the routing of the given  | 
| #assert_routing | Asserts that path and options match both ways; in other words, it verifies that  | 
| #method_missing | ROUTES TODO: These assertions should really work in an integration context. | 
| #with_routing | A helper to make it easier to test different route configurations. | 
::ActionDispatch::Assertions::ResponseAssertions - Included
| #assert_redirected_to | Assert that the redirection options passed in match those of the redirect called in the latest action. | 
| #assert_response | Asserts that the response is one of the following types: | 
Constructor Details
    .new(app)  ⇒ Session 
  
Create and initialize a new Session instance.
# File 'actionpack/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
Class Attribute Details
.default_url_options (rw)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 91
class_attribute :
    .default_url_options?  ⇒ Boolean  (rw)
  
  [ GitHub ]
# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 91
class_attribute :
Instance Attribute Details
#accept (rw)
The Accept header to send.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 161
attr_accessor :accept
#controller (readonly)
A reference to the controller instance used by the last request.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 170
attr_reader :controller
#default_url_options (rw)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 91
class_attribute :
    #default_url_options?  ⇒ Boolean  (rw)
  
  [ GitHub ]
# File 'actionpack/lib/action_dispatch/routing/url_for.rb', line 91
class_attribute :
#host (rw)
The hostname used in the last request.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 152
def host @host || DEFAULT_HOST end
#host=(value) (rw) Also known as: #host!
[ GitHub ]# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 155
attr_writer :host
    #https?  ⇒ Boolean  (readonly)
  
Returns true if the session is mimicking a secure HTTPS request.
if session.https?
  #...
end# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 250
def https? @https end
#remote_addr (rw)
The remote_addr used in the last request.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 158
attr_accessor :remote_addr
#request (readonly)
A reference to the request instance used by the last request.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 173
attr_reader :request
#request_count (rw)
A running counter of the number of requests processed.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 179
attr_accessor :request_count
#response (readonly)
A reference to the response instance used by the last request.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 176
attr_reader :response
Instance Method Details
#cookies
A map of the cookies returned by the last response, and which will be sent with the next request.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 165
def _mock_session. end
#https!(flag = true)
Specify whether or not the session should mimic a secure HTTPS request.
session.https!
session.https!(false)# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 241
def https!(flag = true) @https = flag 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 'actionpack/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
[ GitHub ]# File 'actionpack/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