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::ENV_METHODS, Request::HTTP_METHODS, Request::HTTP_METHOD_LOOKUP, Request::LOCALHOST, Request::RFC2518, Request::RFC2616, Request::RFC3253, Request::RFC3648, Request::RFC3744, 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::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, #content_length, #cookie_jar, #deep_munge, #delete?, #flash, #form_data?, #fullpath, #get?, #head?, #headers, #ip, #key?, #local?, #media_type, #method, #method_symbol, #original_fullpath, #original_url, #patch?, #post?, #put?, #raw_post, #remote_ip, #request_method, #request_method_symbol, #reset_session, #server_software, #session=, #session_options=, #uuid, #xml_http_request?

Methods included from Http::URL

#domain, extract_domain, extract_subdomain, extract_subdomains, #host, #host_with_port, #optional_port, #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

Methods included from Http::Parameters

#parameters, #path_parameters, #path_parameters=, #reset_parameters, #symbolized_path_parameters

Methods included from Http::MimeNegotiation

#accepts, #content_mime_type, #content_type, #format, #format=, #formats, #formats=, #negotiate_mime

Methods included from Http::Cache::Request

#etag_matches?, #fresh?, #if_modified_since, #if_none_match, #if_none_match_etags, #not_modified?

Constructor Details

#initialize(env = {}) ⇒ TestRequest

Returns a new instance of TestRequest.



16
17
18
19
# File 'lib/action_dispatch/testing/test_request.rb', line 16

def initialize(env = {})
  env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
  super(default_env.merge(env))
end

Class Method Details

.new(env = {}) ⇒ Object



12
13
14
# File 'lib/action_dispatch/testing/test_request.rb', line 12

def self.new(env = {})
  super
end

Instance Method Details

#accept=(mime_types) ⇒ Object



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

def accept=(mime_types)
  @env.delete('action_dispatch.request.accepts')
  @env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_type| mime_type.to_s }.join(",")
end

#action=(action_name) ⇒ Object



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

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

#cookiesObject



68
69
70
# File 'lib/action_dispatch/testing/test_request.rb', line 68

def cookies
  @cookies ||= {}.with_indifferent_access
end

#host=(host) ⇒ Object



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

def host=(host)
  @env['HTTP_HOST'] = host
end

#if_modified_since=(last_modified) ⇒ Object



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

def if_modified_since=(last_modified)
  @env['HTTP_IF_MODIFIED_SINCE'] = last_modified
end

#if_none_match=(etag) ⇒ Object



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

def if_none_match=(etag)
  @env['HTTP_IF_NONE_MATCH'] = etag
end

#path=(path) ⇒ Object



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

def path=(path)
  @env['PATH_INFO'] = path
end

#port=(number) ⇒ Object



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

def port=(number)
  @env['SERVER_PORT'] = number.to_i
end

#rack_cookiesObject



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

alias :rack_cookies :cookies

#remote_addr=(addr) ⇒ Object



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

def remote_addr=(addr)
  @env['REMOTE_ADDR'] = addr
end

#request_method=(method) ⇒ Object



21
22
23
# File 'lib/action_dispatch/testing/test_request.rb', line 21

def request_method=(method)
  @env['REQUEST_METHOD'] = method.to_s.upcase
end

#request_uri=(uri) ⇒ Object



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

def request_uri=(uri)
  @env['REQUEST_URI'] = uri
end

#user_agent=(user_agent) ⇒ Object



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

def user_agent=(user_agent)
  @env['HTTP_USER_AGENT'] = user_agent
end