Class: ActionDispatch::TestRequest

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

Direct Known Subclasses

ActionController::TestRequest

Constant Summary

DEFAULT_ENV =
Rack::MockRequest.env_for('/')

Constants inherited from Request

Request::HTTP_METHODS, Request::HTTP_METHOD_LOOKUP, Request::LOCALHOST, Request::TRUSTED_PROXIES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Request

#GET, #POST, #authorization, #body, #body_stream, #content_length, #cookie_jar, #delete?, #flash, #forgery_whitelisted?, #form_data?, #fullpath, #get?, #head?, #headers, #ip, #key?, #local?, #media_type, #method, #method_symbol, #post?, #put?, #raw_post, #remote_ip, #request_method, #request_method_symbol, #reset_session, #server_software, #session=, #session_options=, #xml_http_request?

Methods included from Http::URL

#domain, #host, #host_with_port, #port, #port_string, #protocol, #raw_host_with_port, #request_uri, #scheme, #server_port, #ssl?, #standard_port, #standard_port?, #subdomain, #subdomains, #url

Methods included from Http::FilterParameters

#filtered_env, #filtered_parameters

Methods included from ActiveSupport::Concern

#append_features, extended, #included

Methods included from Http::Parameters

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

Methods included from Http::MimeNegotiation

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

Methods included from Http::Cache::Request

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

Constructor Details

#initialize(env = {}) ⇒ TestRequest



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

def initialize(env = {})
  env = Rails.application.env_defaults.merge(env) if defined?(Rails.application)
  super(DEFAULT_ENV.merge(env))

  self.host        = 'test.host'
  self.remote_addr = '0.0.0.0'
  self.user_agent  = 'Rails Testing'
end

Class Method Details

.new(env = {}) ⇒ Object



8
9
10
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 8

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

Instance Method Details

#accept=(mime_types) ⇒ Object



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

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

#action=(action_name) ⇒ Object



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

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

#cookiesObject



72
73
74
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 72

def cookies
  @cookies ||= super
end

#envObject



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

def env
  write_cookies!
  delete_nil_values!
  super
end

#host=(host) ⇒ Object



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

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

#if_modified_since=(last_modified) ⇒ Object



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

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

#if_none_match=(etag) ⇒ Object



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

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

#path=(path) ⇒ Object



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

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

#port=(number) ⇒ Object



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

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

#remote_addr=(addr) ⇒ Object



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

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

#request_method=(method) ⇒ Object



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

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

#request_uri=(uri) ⇒ Object



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

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

#user_agent=(user_agent) ⇒ Object



63
64
65
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 63

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