Class: ActionDispatch::TestRequest
- Inherits:
-
Request
show all
- Defined in:
- actionpack/lib/action_dispatch/testing/test_request.rb
Constant Summary
collapse
- DEFAULT_ENV =
Rack::MockRequest.env_for('/')
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
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, #delete?, #flash, #form_data?, #fullpath, #get?, #head?, #headers, #ip, #key?, #local?, #media_type, #method, #method_symbol, #original_fullpath, #original_url, #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
#filtered_env, #filtered_parameters, #filtered_path
#append_features, extended, #included
#parameters, #path_parameters, #path_parameters=, #reset_parameters, #symbolized_path_parameters
#accepts, #content_mime_type, #content_type, #format, #format=, #formats, #negotiate_mime
#etag_matches?, #fresh?, #if_modified_since, #if_none_match, #not_modified?
Constructor Details
#initialize(env = {}) ⇒ TestRequest
Returns a new instance of TestRequest.
14
15
16
17
18
19
20
21
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 14
def initialize(env = {})
env = Rails.application.env_config.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
10
11
12
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 10
def self.new(env = {})
super
end
|
Instance Method Details
#accept=(mime_types) ⇒ Object
63
64
65
66
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 63
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
43
44
45
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 43
def action=(action_name)
path_parameters["action"] = action_name.to_s
end
|
70
71
72
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 70
def cookies
@cookies ||= {}.with_indifferent_access
end
|
#host=(host) ⇒ Object
27
28
29
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 27
def host=(host)
@env['HTTP_HOST'] = host
end
|
#if_modified_since=(last_modified) ⇒ Object
47
48
49
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 47
def if_modified_since=(last_modified)
@env['HTTP_IF_MODIFIED_SINCE'] = last_modified
end
|
#if_none_match=(etag) ⇒ Object
51
52
53
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 51
def if_none_match=(etag)
@env['HTTP_IF_NONE_MATCH'] = etag
end
|
#path=(path) ⇒ Object
39
40
41
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 39
def path=(path)
@env['PATH_INFO'] = path
end
|
#port=(number) ⇒ Object
31
32
33
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 31
def port=(number)
@env['SERVER_PORT'] = number.to_i
end
|
#rack_cookies ⇒ Object
68
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 68
alias :rack_cookies :cookies
|
#remote_addr=(addr) ⇒ Object
55
56
57
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 55
def remote_addr=(addr)
@env['REMOTE_ADDR'] = addr
end
|
#request_method=(method) ⇒ Object
23
24
25
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 23
def request_method=(method)
@env['REQUEST_METHOD'] = method.to_s.upcase
end
|
#request_uri=(uri) ⇒ Object
35
36
37
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 35
def request_uri=(uri)
@env['REQUEST_URI'] = uri
end
|
#user_agent=(user_agent) ⇒ Object
59
60
61
|
# File 'actionpack/lib/action_dispatch/testing/test_request.rb', line 59
def user_agent=(user_agent)
@env['HTTP_USER_AGENT'] = user_agent
end
|