Class: ActionController::TestRequest
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
self,
::ActionDispatch::TestRequest ,
::ActionDispatch::Request ,
::ActionDispatch::Flash::RequestMethods ,
Rack::Request::Env,
::ActionDispatch::PermissionsPolicy::Request ,
::ActionDispatch::ContentSecurityPolicy::Request ,
::ActionDispatch::Http::URL ,
::ActionDispatch::Http::FilterParameters ,
::ActionDispatch::Http::Parameters ,
::ActionDispatch::Http::MimeNegotiation ,
::ActionDispatch::Http::Cache::Request ,
Rack::Request::Helpers
|
|
Inherits: |
ActionDispatch::TestRequest
|
Defined in: | actionpack/lib/action_controller/test_case.rb |
Overview
TestCase
will be deprecated and moved to a gem in the future. Please use ::ActionDispatch::IntegrationTest
going forward.
Constant Summary
-
DEFAULT_ENV =
# File 'actionpack/lib/action_controller/test_case.rb', line 39ActionDispatch::TestRequest::DEFAULT_ENV.dup
-
ENCODER =
# File 'actionpack/lib/action_controller/test_case.rb', line 143Class.new do include Rack::Test::Utils def should_multipart?(params) # FIXME: lifted from Rack-Test. We should push this separation upstream. multipart = false query = lambda { |value| case value when Array value.each(&query) when Hash value.values.each(&query) when Rack::Test::UploadedFile multipart = true end } params.values.each(&query) multipart end public :build_multipart def content_type "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}" end end.new
::ActionDispatch::Http::Cache::Request
- Included
HTTP_IF_MODIFIED_SINCE, HTTP_IF_NONE_MATCH
::ActionDispatch::Http::MimeNegotiation
- Included
BROWSER_LIKE_ACCEPTS, RESCUABLE_MIME_FORMAT_ERRORS
::ActionDispatch::Http::Parameters
- Included
DEFAULT_PARSERS, PARAMETERS_KEY
::ActionDispatch::Http::FilterParameters
- Included
ENV_MATCH, NULL_ENV_FILTER, NULL_PARAM_FILTER
::ActionDispatch::Http::URL
- Included
HOST_REGEXP, IP_HOST_REGEXP, PROTOCOL_REGEXP
::ActionDispatch::ContentSecurityPolicy::Request
- Included
NONCE, NONCE_DIRECTIVES, NONCE_GENERATOR, POLICY, POLICY_REPORT_ONLY
::ActionDispatch::PermissionsPolicy::Request
- Included
::ActionDispatch::Request
- Inherited
ACTION_DISPATCH_REQUEST_ID, ENV_METHODS, HTTP_METHODS, HTTP_METHOD_LOOKUP, LOCALHOST, PASS_NOT_FOUND, RFC2518, RFC2616, RFC3253, RFC3648, RFC3744, RFC4791, RFC5323, RFC5789, TRANSFER_ENCODING
::ActionDispatch::TestRequest
- Inherited
Class Attribute Summary
::ActionDispatch::Request
- Inherited
.ignore_accept_header, | |
.parameter_parsers | Returns the parameter parsers. |
Class Method Summary
-
.create(controller_class)
Create a new test request with default
env
values. - .new(env, session, controller_class) ⇒ TestRequest constructor
- .new_session
- .default_env private
::ActionDispatch::TestRequest
- Inherited
.create | Create a new test request with default |
.default_env |
::ActionDispatch::Request
- Inherited
Instance Attribute Summary
- #content_type=(type) writeonly
- #controller_class readonly
- #query_string=(string) writeonly
::ActionDispatch::TestRequest
- Inherited
#accept=, #action=, #host=, #if_modified_since=, #if_none_match=, #path=, #port=, #remote_addr=, #request_method=, #request_uri=, #user_agent= |
::ActionDispatch::Request
- Inherited
#form_data? | Determine whether the request body contains form-data by checking the request |
#ignore_accept_header, | |
#local? | True if the request came from localhost, 127.0.0.1, or ::1. |
#rack_request, | |
#remote_ip | Returns the IP address of client as a |
#remote_ip=, | |
#request_id | Returns the unique request id, which is based on either the |
#request_method | Returns the HTTP method that the application should see. |
#request_parameters | Alias for ActionDispatch::Request#POST. |
#request_parameters=, | |
#route_uri_pattern | Returns the URI pattern of the matched route for the request, using the same format as ‘bin/rails routes`: |
#session_options=, | |
#uuid | Alias for ActionDispatch::Request#request_id. |
#xhr? | Alias for ActionDispatch::Request#xml_http_request?. |
#xml_http_request? | Returns true if the |
#controller_instance, #controller_instance=, #request_id=, #request_method=, #route_uri_pattern=, #routes, #routes=, #session= |
::ActionDispatch::Flash::RequestMethods
- Included
::ActionDispatch::PermissionsPolicy::Request
- Included
::ActionDispatch::ContentSecurityPolicy::Request
- Included
::ActionDispatch::Http::URL
- Included
#secure_protocol, | |
#standard_port | Returns the standard port number for this request’s protocol. |
#standard_port? | Returns whether this request is using the standard port. |
#tld_length |
::ActionDispatch::Http::Parameters
- Included
#path_parameters | Returns a hash with the parameters used to form the path of the request. |
#path_parameters= |
::ActionDispatch::Http::MimeNegotiation
- Included
#formats, | |
#formats= | Sets the formats by string extensions. |
#should_apply_vary_header?, #variant, | |
#variant= | Sets the variant for template. |
#params_readable?, #has_content_type? |
::ActionDispatch::Http::Cache::Request
- Included
Instance Method Summary
- #assign_parameters(routes, controller_path, action, parameters, generated_path, query_string_keys)
- #params_parsers private
::ActionDispatch::Request
- Inherited
#authorization | Returns the authorization header regardless of whether it was specified directly or through one of the proxy alternatives. |
#body | The request body is an |
#commit_csrf_token, #commit_flash, | |
#content_length | Returns the content length of the request as an integer. |
#controller_class, #controller_class_for, | |
#fullpath | Returns the |
#GET | Override Rack’s GET method to support indifferent access. |
#headers | Provides access to the request’s HTTP headers, for example: |
#http_auth_salt, | |
#ip | Returns the IP address of client as a |
#key? | Returns true if the request has a header matching the given key parameter. |
#logger, | |
#media_type | The |
#method | Returns the original value of the environment’s REQUEST_METHOD, even if it was overridden by middleware. |
#method_symbol | Returns a symbol form of the |
#original_fullpath | Returns a |
#original_url | Returns the original request URL as a |
#POST | Override Rack’s POST method to support indifferent access. |
#query_parameters | Alias for ActionDispatch::Request#GET. |
#raw_post | Read the request body. |
#request_method_symbol | Returns a symbol form of the |
#request_parameters_list, #reset_csrf_token, #reset_session, | |
#send_early_hints | Early Hints is an HTTP/2 status code that indicates hints to help a client start making preparations for processing the final response. |
#server_software | Returns the lowercase name of the HTTP server software. |
#check_method, #default_session, #fallback_request_parameters, #read_body_stream, #reset_stream, #body_stream, #commit_cookie_jar!, #engine_script_name, #engine_script_name=, #inspect, #raw_request_method |
::ActionDispatch::Flash::RequestMethods
- Included
::ActionDispatch::ContentSecurityPolicy::Request
- Included
::ActionDispatch::Http::URL
- Included
#domain | Returns the domain part of a host, such as “rubyonrails.org” in “www.rubyonrails.org”. |
#host | Returns the host for this request, such as “example.com”. |
#host_with_port | Returns a host:port string for this request, such as “example.com” or “example.com:8080”. |
#initialize, | |
#optional_port | Returns a number port suffix like 8080 if the port number of this request is not the default HTTP port 80 or HTTPS port 443. |
#port | Returns the port number of this request as an integer. |
#port_string | Returns a string port suffix, including colon, like “:8080” if the port number of this request is not the default HTTP port 80 or HTTPS port 443. |
#protocol | Returns ‘https://’ if this is an SSL request and ‘http://’ otherwise. |
#raw_host_with_port | Returns the host and port for this request, such as “example.com:8080”. |
#server_port | Returns the requested port, such as 8080, based on SERVER_PORT. |
#subdomain | Returns all the subdomains as a string, so |
#subdomains | Returns all the subdomains as an array, so |
#url | Returns the complete URL used for this request. |
::ActionDispatch::Http::FilterParameters
- Included
#filtered_env | Returns a hash of request.env with all sensitive data replaced. |
#filtered_parameters | Returns a hash of parameters with all sensitive data replaced. |
#filtered_path | Reconstructs a path with all sensitive GET parameters replaced. |
#initialize, | |
#parameter_filter | Returns the |
#env_filter, #filtered_query_string, #parameter_filter_for |
::ActionDispatch::Http::Parameters
- Included
#parameters | Returns both GET and POST parameters in a single hash. |
#params | Alias for ActionDispatch::Http::Parameters#parameters. |
#log_parse_error_once, #params_parsers, #parse_formatted_parameters |
::ActionDispatch::Http::MimeNegotiation
- Included
#accepts | Returns the accepted MIME type for the request. |
#content_mime_type | The MIME type of the HTTP request, such as [Mime](:xml). |
#format | Returns the MIME type for the format used in the request. |
#format= | Sets the format by string extension, which can be used to force custom formats that are not controlled by the extension. |
#negotiate_mime | Returns the first MIME type that matches the provided array of MIME types. |
#format_from_path_extension, #use_accept_header, #valid_accept_header |
::ActionDispatch::Http::Cache::Request
- Included
#etag_matches?, | |
#fresh? | Check response freshness (‘Last-Modified` and |
#if_modified_since, #if_none_match, #if_none_match_etags, #not_modified? |
Constructor Details
.new(env, session, controller_class) ⇒ TestRequest
# File 'actionpack/lib/action_controller/test_case.rb', line 61
def initialize(env, session, controller_class) super(env) self.session = session self. = TestSession::DEFAULT_OPTIONS.dup @controller_class = controller_class @custom_param_parsers = { xml: lambda { |raw_post| Hash.from_xml(raw_post)["hash"] } } end
Class Method Details
.create(controller_class)
Create a new test request with default env
values.
# File 'actionpack/lib/action_controller/test_case.rb', line 49
def self.create(controller_class) env = {} env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application env["rack.request.cookie_hash"] = {}.with_indifferent_access new(default_env.merge(env), new_session, controller_class) end
.default_env (private)
[ GitHub ]# File 'actionpack/lib/action_controller/test_case.rb', line 56
def self.default_env DEFAULT_ENV end
.new_session
[ GitHub ]# File 'actionpack/lib/action_controller/test_case.rb', line 42
def self.new_session TestSession.new end
Instance Attribute Details
#content_type=(type) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_controller/test_case.rb', line 76
def content_type=(type) set_header "CONTENT_TYPE", type end
#controller_class (readonly)
[ GitHub ]# File 'actionpack/lib/action_controller/test_case.rb', line 46
attr_reader :controller_class
#query_string=(string) (writeonly)
[ GitHub ]# File 'actionpack/lib/action_controller/test_case.rb', line 72
def query_string=(string) set_header Rack::QUERY_STRING, string end
Instance Method Details
#assign_parameters(routes, controller_path, action, parameters, generated_path, query_string_keys)
[ GitHub ]# File 'actionpack/lib/action_controller/test_case.rb', line 80
def assign_parameters(routes, controller_path, action, parameters, generated_path, query_string_keys) non_path_parameters = {} path_parameters = {} parameters.each do |key, value| if query_string_keys.include?(key) non_path_parameters[key] = value else if value.is_a?(Array) value = value.map(&:to_param) else value = value.to_param end path_parameters[key.to_sym] = value end end if get? if query_string.blank? self.query_string = non_path_parameters.to_query end else if ENCODER.should_multipart?(non_path_parameters) self.content_type = ENCODER.content_type data = ENCODER.build_multipart non_path_parameters else fetch_header("CONTENT_TYPE") do |k| set_header k, "application/x-www-form-urlencoded" end case content_mime_type&.to_sym when nil raise "Unknown Content-Type: #{content_type}" when :json data = ActiveSupport::JSON.encode(non_path_parameters) when :xml data = non_path_parameters.to_xml when :url_encoded_form data = non_path_parameters.to_query else @custom_param_parsers[content_mime_type.symbol] = ->(_) { non_path_parameters } data = non_path_parameters.to_query end end data_stream = StringIO.new(data.b) set_header "CONTENT_LENGTH", data_stream.length.to_s set_header "rack.input", data_stream end fetch_header("PATH_INFO") do |k| set_header k, generated_path end fetch_header("ORIGINAL_FULLPATH") do |k| set_header k, fullpath end path_parameters[:controller] = controller_path path_parameters[:action] = action self.path_parameters = path_parameters end
#params_parsers (private)
[ GitHub ]# File 'actionpack/lib/action_controller/test_case.rb', line 171
def params_parsers super.merge @custom_param_parsers end