Class: ActionDispatch::TestRequest
- Defined in:
- actionpack/lib/action_dispatch/testing/test_request.rb
Direct Known Subclasses
ActionCable::Connection::TestRequest, ActionController::TestRequest
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
Constants included from FeaturePolicy::Request
FeaturePolicy::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, #authenticated_encrypted_cookie_salt, #authorization, #body, #body_stream, #commit_cookie_jar!, #commit_flash, #content_length, #controller_class, #controller_class_for, #controller_instance, #controller_instance=, #cookie_jar, #cookie_jar=, #cookies_digest, #cookies_rotations, #cookies_same_site_protection, #cookies_serializer, empty, #encrypted_cookie_cipher, #encrypted_cookie_salt, #encrypted_signed_cookie_salt, #engine_script_name, #engine_script_name=, #form_data?, #fullpath, #have_cookie_jar?, #headers, #http_auth_salt, #initialize, #ip, #key?, #key_generator, #local?, #logger, #media_type, #method, #method_symbol, #original_fullpath, #original_url, #raw_post, #remote_ip, #remote_ip=, #request_id, #request_id=, #request_method, #request_method_symbol, #request_parameters=, #reset_session, #routes, #routes=, #secret_key_base, #send_early_hints, #server_software, #session=, #session_options=, #show_exceptions?, #signed_cookie_digest, #signed_cookie_salt, #ssl?, #use_authenticated_cookie_encryption, #use_cookies_with_metadata, #xml_http_request?
Methods included from FeaturePolicy::Request
#feature_policy, #feature_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
Methods included from Http::Parameters
#parameters, #path_parameters, #path_parameters=
Methods included from ActiveSupport::Concern
#append_features, #class_methods, extended, #included
Methods included from Http::MimeNegotiation
#accepts, #content_mime_type, #content_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?
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.
15 16 17 18 19 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 15 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
66 67 68 69 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 66 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
46 47 48 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 46 def action=(action_name) path_parameters[:action] = action_name.to_s end |
#host=(host) ⇒ Object
30 31 32 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 30 def host=(host) set_header("HTTP_HOST", host) end |
#if_modified_since=(last_modified) ⇒ Object
50 51 52 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 50 def if_modified_since=(last_modified) set_header("HTTP_IF_MODIFIED_SINCE", last_modified) end |
#if_none_match=(etag) ⇒ Object
54 55 56 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 54 def if_none_match=(etag) set_header("HTTP_IF_NONE_MATCH", etag) end |
#path=(path) ⇒ Object
42 43 44 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 42 def path=(path) set_header("PATH_INFO", path) end |
#port=(number) ⇒ Object
34 35 36 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 34 def port=(number) set_header("SERVER_PORT", number.to_i) end |
#remote_addr=(addr) ⇒ Object
58 59 60 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 58 def remote_addr=(addr) set_header("REMOTE_ADDR", addr) end |
#request_method=(method) ⇒ Object
26 27 28 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 26 def request_method=(method) super(method.to_s.upcase) end |
#request_uri=(uri) ⇒ Object
38 39 40 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 38 def request_uri=(uri) set_header("REQUEST_URI", uri) end |
#user_agent=(user_agent) ⇒ Object
62 63 64 |
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 62 def user_agent=(user_agent) set_header("HTTP_USER_AGENT", user_agent) end |