Class: ActionDispatch::TestRequest
- Defined in:
- lib/action_dispatch/testing/test_request.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_ENV =
Rack::MockRequest.env_for("/", "HTTP_HOST" => "test.host".b, "REMOTE_ADDR" => "0.0.0.0".b, "HTTP_USER_AGENT" => "Rails Testing".b, )
Constants inherited from Request
Request::ACTION_DISPATCH_REQUEST_ID, Request::ENV_METHODS, Request::HTTP_METHODS, Request::HTTP_METHOD_LOOKUP, Request::LOCALHOST, Request::PASS_NOT_FOUND, Request::RFC2518, Request::RFC2616, Request::RFC3253, Request::RFC3648, Request::RFC3744, Request::RFC4791, Request::RFC5323, Request::RFC5789, Request::TRANSFER_ENCODING
Constants included from PermissionsPolicy::Request
PermissionsPolicy::Request::POLICY
Constants included from ContentSecurityPolicy::Request
ContentSecurityPolicy::Request::NONCE, ContentSecurityPolicy::Request::NONCE_DIRECTIVES, ContentSecurityPolicy::Request::NONCE_GENERATOR, ContentSecurityPolicy::Request::POLICY, ContentSecurityPolicy::Request::POLICY_REPORT_ONLY
Constants included from Http::URL
Http::URL::HOST_REGEXP, Http::URL::IP_HOST_REGEXP, Http::URL::PROTOCOL_REGEXP
Constants included from Http::FilterParameters
Http::FilterParameters::ENV_MATCH, Http::FilterParameters::NULL_ENV_FILTER, Http::FilterParameters::NULL_PARAM_FILTER
Constants included from Http::Parameters
Http::Parameters::DEFAULT_PARSERS, Http::Parameters::PARAMETERS_KEY
Constants included from Http::MimeNegotiation
Http::MimeNegotiation::RESCUABLE_MIME_FORMAT_ERRORS
Constants included from Http::Cache::Request
Http::Cache::Request::HTTP_IF_MODIFIED_SINCE, Http::Cache::Request::HTTP_IF_NONE_MATCH
Class Method Summary collapse
-
.create(env = {}) ⇒ Object
Create a new test request with default ‘env` values.
Instance Method Summary collapse
- #accept=(mime_types) ⇒ Object
- #action=(action_name) ⇒ Object
- #host=(host) ⇒ Object
- #if_modified_since=(last_modified) ⇒ Object
- #if_none_match=(etag) ⇒ Object
- #path=(path) ⇒ Object
- #port=(number) ⇒ Object
- #remote_addr=(addr) ⇒ Object
- #request_method=(method) ⇒ Object
- #request_uri=(uri) ⇒ Object
- #user_agent=(user_agent) ⇒ Object
Methods inherited from Request
#GET, #POST, #authorization, #body, #body_stream, #commit_cookie_jar!, #commit_csrf_token, #commit_flash, #content_length, #controller_class, #controller_class_for, #controller_instance, #controller_instance=, empty, #engine_script_name, #engine_script_name=, #form_data?, #fullpath, #headers, #http_auth_salt, #initialize, #inspect, #ip, #key?, #local?, #logger, #media_type, #method, #method_symbol, #original_fullpath, #original_url, #raw_post, #raw_request_method, #remote_ip, #remote_ip=, #request_id, #request_id=, #request_method, #request_method_symbol, #request_parameters=, #reset_csrf_token, #reset_session, #route_uri_pattern, #route_uri_pattern=, #routes, #routes=, #send_early_hints, #server_software, #session=, #session_options=, #xml_http_request?
Methods included from PermissionsPolicy::Request
#permissions_policy, #permissions_policy=
Methods included from ContentSecurityPolicy::Request
#content_security_policy, #content_security_policy=, #content_security_policy_nonce, #content_security_policy_nonce_directives, #content_security_policy_nonce_directives=, #content_security_policy_nonce_generator, #content_security_policy_nonce_generator=, #content_security_policy_report_only, #content_security_policy_report_only=
Methods included from Http::URL
#domain, extract_domain, extract_subdomain, extract_subdomains, full_url_for, #host, #host_with_port, #initialize, #optional_port, path_for, #port, #port_string, #protocol, #raw_host_with_port, #server_port, #standard_port, #standard_port?, #subdomain, #subdomains, #url, url_for
Methods included from Http::FilterParameters
#filtered_env, #filtered_parameters, #filtered_path, #initialize, #parameter_filter
Methods included from Http::Parameters
#parameters, #path_parameters, #path_parameters=
Methods included from Http::MimeNegotiation
#accepts, #content_mime_type, #format, #format=, #formats, #formats=, #has_content_type?, #negotiate_mime, #should_apply_vary_header?, #variant, #variant=
Methods included from Http::Cache::Request
#etag_matches?, #fresh?, #if_modified_since, #if_none_match, #if_none_match_etags, #not_modified?
Methods included from Flash::RequestMethods
#commit_flash, #flash, #flash=, #flash_hash, #reset_session
Constructor Details
This class inherits a constructor from ActionDispatch::Request
Class Method Details
.create(env = {}) ⇒ Object
Create a new test request with default ‘env` values.
17 18 19 20 21 |
# File 'lib/action_dispatch/testing/test_request.rb', line 17 def self.create(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)) end |
Instance Method Details
#accept=(mime_types) ⇒ Object
68 69 70 71 |
# File 'lib/action_dispatch/testing/test_request.rb', line 68 def accept=(mime_types) delete_header("action_dispatch.request.accepts") set_header("HTTP_ACCEPT", Array(mime_types).collect(&:to_s).join(",")) end |
#action=(action_name) ⇒ Object
48 49 50 |
# File 'lib/action_dispatch/testing/test_request.rb', line 48 def action=(action_name) path_parameters[:action] = action_name.to_s end |
#host=(host) ⇒ Object
32 33 34 |
# File 'lib/action_dispatch/testing/test_request.rb', line 32 def host=(host) set_header("HTTP_HOST", host) end |
#if_modified_since=(last_modified) ⇒ Object
52 53 54 |
# File 'lib/action_dispatch/testing/test_request.rb', line 52 def if_modified_since=(last_modified) set_header("HTTP_IF_MODIFIED_SINCE", last_modified) end |
#if_none_match=(etag) ⇒ Object
56 57 58 |
# File 'lib/action_dispatch/testing/test_request.rb', line 56 def if_none_match=(etag) set_header("HTTP_IF_NONE_MATCH", etag) end |
#path=(path) ⇒ Object
44 45 46 |
# File 'lib/action_dispatch/testing/test_request.rb', line 44 def path=(path) set_header("PATH_INFO", path) end |
#port=(number) ⇒ Object
36 37 38 |
# File 'lib/action_dispatch/testing/test_request.rb', line 36 def port=(number) set_header("SERVER_PORT", number) end |
#remote_addr=(addr) ⇒ Object
60 61 62 |
# File 'lib/action_dispatch/testing/test_request.rb', line 60 def remote_addr=(addr) set_header("REMOTE_ADDR", addr) end |
#request_method=(method) ⇒ Object
28 29 30 |
# File 'lib/action_dispatch/testing/test_request.rb', line 28 def request_method=(method) super(method.to_s.upcase) end |
#request_uri=(uri) ⇒ Object
40 41 42 |
# File 'lib/action_dispatch/testing/test_request.rb', line 40 def request_uri=(uri) set_header("REQUEST_URI", uri) end |
#user_agent=(user_agent) ⇒ Object
64 65 66 |
# File 'lib/action_dispatch/testing/test_request.rb', line 64 def user_agent=(user_agent) set_header("HTTP_USER_AGENT", user_agent) end |