Class: ActionDispatch::TestRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/action_dispatch/testing/test_request.rb

Direct Known Subclasses

ActionController::TestRequest

Constant Summary collapse

DEFAULT_ENV =
Rack::MockRequest.env_for("/",
  "HTTP_HOST"                => "test.host",
  "REMOTE_ADDR"              => "0.0.0.0",
  "HTTP_USER_AGENT"          => "Rails Testing",
)

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 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::Cache::Request

Http::Cache::Request::HTTP_IF_MODIFIED_SINCE, Http::Cache::Request::HTTP_IF_NONE_MATCH

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Request

#GET, #POST, #authorization, #body, #body_stream, #commit_cookie_jar!, #commit_flash, #content_length, #controller_class, #controller_instance, #controller_instance=, #cookie_jar, #cookie_jar=, #cookies_digest, #cookies_serializer, empty, #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, #secret_token, #server_software, #session=, #session_options=, #show_exceptions?, #signed_cookie_salt, #ssl?, #xml_http_request?

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 Http::MimeNegotiation

#accepts, #content_mime_type, #content_type, #format, #format=, #formats, #formats=, #has_content_type?, #negotiate_mime, #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



13
14
15
16
17
# File 'lib/action_dispatch/testing/test_request.rb', line 13

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



64
65
66
67
# File 'lib/action_dispatch/testing/test_request.rb', line 64

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



44
45
46
# File 'lib/action_dispatch/testing/test_request.rb', line 44

def action=(action_name)
  path_parameters[:action] = action_name.to_s
end

#host=(host) ⇒ Object



28
29
30
# File 'lib/action_dispatch/testing/test_request.rb', line 28

def host=(host)
  set_header("HTTP_HOST", host)
end

#if_modified_since=(last_modified) ⇒ Object



48
49
50
# File 'lib/action_dispatch/testing/test_request.rb', line 48

def if_modified_since=(last_modified)
  set_header("HTTP_IF_MODIFIED_SINCE", last_modified)
end

#if_none_match=(etag) ⇒ Object



52
53
54
# File 'lib/action_dispatch/testing/test_request.rb', line 52

def if_none_match=(etag)
  set_header("HTTP_IF_NONE_MATCH", etag)
end

#path=(path) ⇒ Object



40
41
42
# File 'lib/action_dispatch/testing/test_request.rb', line 40

def path=(path)
  set_header("PATH_INFO", path)
end

#port=(number) ⇒ Object



32
33
34
# File 'lib/action_dispatch/testing/test_request.rb', line 32

def port=(number)
  set_header("SERVER_PORT", number.to_i)
end

#remote_addr=(addr) ⇒ Object



56
57
58
# File 'lib/action_dispatch/testing/test_request.rb', line 56

def remote_addr=(addr)
  set_header("REMOTE_ADDR", addr)
end

#request_method=(method) ⇒ Object



24
25
26
# File 'lib/action_dispatch/testing/test_request.rb', line 24

def request_method=(method)
  super(method.to_s.upcase)
end

#request_uri=(uri) ⇒ Object



36
37
38
# File 'lib/action_dispatch/testing/test_request.rb', line 36

def request_uri=(uri)
  set_header("REQUEST_URI", uri)
end

#user_agent=(user_agent) ⇒ Object



60
61
62
# File 'lib/action_dispatch/testing/test_request.rb', line 60

def user_agent=(user_agent)
  set_header("HTTP_USER_AGENT", user_agent)
end