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.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/action_controller/test_process.rb', line 29 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.
25 26 27 |
# File 'lib/action_controller/test_process.rb', line 25 def @cookies end |
#env ⇒ Object
Returns the value of attribute env.
26 27 28 |
# File 'lib/action_controller/test_process.rb', line 26 def env @env end |
#host ⇒ Object
Returns the value of attribute host.
27 28 29 |
# File 'lib/action_controller/test_process.rb', line 27 def host @host end |
#path ⇒ Object
Returns the value of attribute path.
26 27 28 |
# File 'lib/action_controller/test_process.rb', line 26 def path @path end |
#query_parameters ⇒ Object
Returns the value of attribute query_parameters.
26 27 28 |
# File 'lib/action_controller/test_process.rb', line 26 def query_parameters @query_parameters end |
#request_parameters ⇒ Object
Returns the value of attribute request_parameters.
26 27 28 |
# File 'lib/action_controller/test_process.rb', line 26 def request_parameters @request_parameters end |
#session ⇒ Object
Returns the value of attribute session.
26 27 28 |
# File 'lib/action_controller/test_process.rb', line 26 def session @session end |
#session_options ⇒ Object
Returns the value of attribute session_options.
25 26 27 |
# File 'lib/action_controller/test_process.rb', line 25 def @session_options end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
27 28 29 |
# File 'lib/action_controller/test_process.rb', line 27 def user_agent @user_agent end |
Instance Method Details
#accept=(mime_types) ⇒ Object
78 79 80 |
# File 'lib/action_controller/test_process.rb', line 78 def accept=(mime_types) @env["HTTP_ACCEPT"] = Array(mime_types).collect { |mime_types| mime_types.to_s }.join(",") end |
#action=(action_name) ⇒ Object
60 61 62 63 |
# File 'lib/action_controller/test_process.rb', line 60 def action=(action_name) @query_parameters.update({ "action" => action_name }) @parameters = nil end |
#assign_parameters(controller_path, action, parameters) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/action_controller/test_process.rb', line 98 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.
45 46 47 |
# File 'lib/action_controller/test_process.rb', line 45 def body StringIO.new(raw_post) end |
#port=(number) ⇒ Object
55 56 57 58 |
# File 'lib/action_controller/test_process.rb', line 55 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.
51 52 53 |
# File 'lib/action_controller/test_process.rb', line 51 def raw_post env['RAW_POST_DATA'] ||= returning(url_encoded_request_parameters) { |b| b.force_encoding(Encoding::BINARY) if b.respond_to?(:force_encoding) } end |
#recycle! ⇒ Object
118 119 120 121 122 123 |
# File 'lib/action_controller/test_process.rb', line 118 def recycle! self.request_parameters = {} self.query_parameters = {} self.path_parameters = {} @request_method, @accepts, @content_type = nil, nil, nil end |
#referer ⇒ Object
125 126 127 |
# File 'lib/action_controller/test_process.rb', line 125 def referer @env["HTTP_REFERER"] end |
#remote_addr ⇒ Object
86 87 88 |
# File 'lib/action_controller/test_process.rb', line 86 def remote_addr @env['REMOTE_ADDR'] end |
#remote_addr=(addr) ⇒ Object
82 83 84 |
# File 'lib/action_controller/test_process.rb', line 82 def remote_addr=(addr) @env['REMOTE_ADDR'] = addr end |
#request_uri ⇒ Object
90 91 92 |
# File 'lib/action_controller/test_process.rb', line 90 def request_uri @request_uri || super end |
#request_uri=(uri) ⇒ Object
73 74 75 76 |
# File 'lib/action_controller/test_process.rb', line 73 def request_uri=(uri) @request_uri = uri @path = uri.split("?").first end |
#reset_session ⇒ Object
40 41 42 |
# File 'lib/action_controller/test_process.rb', line 40 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.
67 68 69 70 71 |
# File 'lib/action_controller/test_process.rb', line 67 def set_REQUEST_URI(value) @env["REQUEST_URI"] = value @request_uri = nil @path = nil end |