Class: ActionController::TestRequest
- Inherits:
-
AbstractRequest
- Object
- AbstractRequest
- ActionController::TestRequest
- Defined in:
- lib/action_controller/test_process.rb
Overview
:nodoc:
Constant Summary
Constants inherited from AbstractRequest
AbstractRequest::TRUSTED_PROXIES
Instance Attribute Summary collapse
-
#cookies ⇒ Object
Returns the value of attribute cookies.
-
#env ⇒ Object
Returns the value of attribute env.
-
#host ⇒ Object
Returns the value of attribute host.
-
#path ⇒ Object
Returns the value of attribute path.
-
#query_parameters ⇒ Object
Returns the value of attribute query_parameters.
-
#request_parameters ⇒ Object
Returns the value of attribute request_parameters.
-
#session ⇒ Object
Returns the value of attribute session.
-
#session_options ⇒ Object
Returns the value of attribute session_options.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #accept=(mime_types) ⇒ Object
- #action=(action_name) ⇒ Object
- #assign_parameters(controller_path, action, parameters) ⇒ Object
-
#body ⇒ Object
Wraps raw_post in a StringIO.
-
#initialize(query_parameters = nil, request_parameters = nil, session = nil) ⇒ TestRequest
constructor
A new instance of TestRequest.
- #port=(number) ⇒ Object
-
#raw_post ⇒ Object
Either the RAW_POST_DATA environment variable or the URL-encoded request parameters.
- #recycle! ⇒ Object
- #referer ⇒ Object
- #remote_addr ⇒ Object
- #remote_addr=(addr) ⇒ Object
- #request_uri ⇒ Object
- #request_uri=(uri) ⇒ Object
- #reset_session ⇒ Object
-
#set_REQUEST_URI(value) ⇒ Object
Used to check AbstractRequest’s request_uri functionality.
Methods inherited from AbstractRequest
#accepts, clean_up_ajax_request_body!, #content_length, #content_type, #delete?, #domain, extract_content_type_without_parameters, extract_multipart_boundary, #format, #format=, #get?, #head?, #headers, #host_with_port, #method, #parameters, parse_multipart_form_parameters, parse_query_parameters, parse_request_parameters, #path_parameters, #path_parameters=, #port, #port_string, #post?, #protocol, #put?, #query_string, #relative_url_root, #remote_ip, #request_method, #server_software, #ssl?, #standard_port, #subdomains, #symbolized_path_parameters, #url, #xml_http_request?
Constructor Details
#initialize(query_parameters = nil, request_parameters = nil, session = nil) ⇒ TestRequest
Returns a new instance of TestRequest.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/action_controller/test_process.rb', line 28 def initialize(query_parameters = nil, request_parameters = nil, session = nil) @query_parameters = query_parameters || {} @request_parameters = request_parameters || {} @session = session || TestSession.new initialize_containers initialize_default_values super() end |
Instance Attribute Details
#cookies ⇒ Object
Returns the value of attribute cookies.
24 25 26 |
# File 'lib/action_controller/test_process.rb', line 24 def @cookies end |
#env ⇒ Object
Returns the value of attribute env.
25 26 27 |
# File 'lib/action_controller/test_process.rb', line 25 def env @env end |
#host ⇒ Object
Returns the value of attribute host.
26 27 28 |
# File 'lib/action_controller/test_process.rb', line 26 def host @host end |
#path ⇒ Object
Returns the value of attribute path.
25 26 27 |
# File 'lib/action_controller/test_process.rb', line 25 def path @path end |
#query_parameters ⇒ Object
Returns the value of attribute query_parameters.
25 26 27 |
# File 'lib/action_controller/test_process.rb', line 25 def query_parameters @query_parameters end |
#request_parameters ⇒ Object
Returns the value of attribute request_parameters.
25 26 27 |
# File 'lib/action_controller/test_process.rb', line 25 def request_parameters @request_parameters end |
#session ⇒ Object
Returns the value of attribute session.
25 26 27 |
# File 'lib/action_controller/test_process.rb', line 25 def session @session end |
#session_options ⇒ Object
Returns the value of attribute session_options.
24 25 26 |
# File 'lib/action_controller/test_process.rb', line 24 def @session_options end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
26 27 28 |
# File 'lib/action_controller/test_process.rb', line 26 def user_agent @user_agent end |
Instance Method Details
#accept=(mime_types) ⇒ Object
77 78 79 |
# File 'lib/action_controller/test_process.rb', line 77 def accept=(mime_types) @env["HTTP_ACCEPT"] = Array(mime_types).collect { |mime_types| mime_types.to_s }.join(",") end |
#action=(action_name) ⇒ Object
59 60 61 62 |
# File 'lib/action_controller/test_process.rb', line 59 def action=(action_name) @query_parameters.update({ "action" => action_name }) @parameters = nil end |
#assign_parameters(controller_path, action, parameters) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/action_controller/test_process.rb', line 97 def assign_parameters(controller_path, action, parameters) parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action) extra_keys = ActionController::Routing::Routes.extra_keys(parameters) non_path_parameters = get? ? query_parameters : request_parameters parameters.each do |key, value| if value.is_a? Fixnum value = value.to_s elsif value.is_a? Array value = ActionController::Routing::PathSegment::Result.new(value) end if extra_keys.include?(key.to_sym) non_path_parameters[key] = value else path_parameters[key.to_s] = value end end @parameters = nil # reset TestRequest#parameters to use the new path_parameters end |
#body ⇒ Object
Wraps raw_post in a StringIO.
44 45 46 |
# File 'lib/action_controller/test_process.rb', line 44 def body StringIO.new(raw_post) end |
#port=(number) ⇒ Object
54 55 56 57 |
# File 'lib/action_controller/test_process.rb', line 54 def port=(number) @env["SERVER_PORT"] = number.to_i @port_as_int = nil end |
#raw_post ⇒ Object
Either the RAW_POST_DATA environment variable or the URL-encoded request parameters.
50 51 52 |
# File 'lib/action_controller/test_process.rb', line 50 def raw_post env['RAW_POST_DATA'] ||= url_encoded_request_parameters end |
#recycle! ⇒ Object
117 118 119 120 121 122 |
# File 'lib/action_controller/test_process.rb', line 117 def recycle! self.request_parameters = {} self.query_parameters = {} self.path_parameters = {} @request_method, @accepts, @content_type = nil, nil, nil end |
#referer ⇒ Object
124 125 126 |
# File 'lib/action_controller/test_process.rb', line 124 def referer @env["HTTP_REFERER"] end |
#remote_addr ⇒ Object
85 86 87 |
# File 'lib/action_controller/test_process.rb', line 85 def remote_addr @env['REMOTE_ADDR'] end |
#remote_addr=(addr) ⇒ Object
81 82 83 |
# File 'lib/action_controller/test_process.rb', line 81 def remote_addr=(addr) @env['REMOTE_ADDR'] = addr end |
#request_uri ⇒ Object
89 90 91 |
# File 'lib/action_controller/test_process.rb', line 89 def request_uri @request_uri || super end |
#request_uri=(uri) ⇒ Object
72 73 74 75 |
# File 'lib/action_controller/test_process.rb', line 72 def request_uri=(uri) @request_uri = uri @path = uri.split("?").first end |
#reset_session ⇒ Object
39 40 41 |
# File 'lib/action_controller/test_process.rb', line 39 def reset_session @session = TestSession.new end |
#set_REQUEST_URI(value) ⇒ Object
Used to check AbstractRequest’s request_uri functionality. Disables the use of @path and @request_uri so superclass can handle those.
66 67 68 69 70 |
# File 'lib/action_controller/test_process.rb', line 66 def set_REQUEST_URI(value) @env["REQUEST_URI"] = value @request_uri = nil @path = nil end |