Class: ActionController::TestRequest

Inherits:
AbstractRequest show all
Defined in:
lib/action_controller/test_process.rb

Overview

:nodoc:

Constant Summary

Constants inherited from AbstractRequest

AbstractRequest::TRUSTED_PROXIES

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cookiesObject

Returns the value of attribute cookies.



24
25
26
# File 'lib/action_controller/test_process.rb', line 24

def cookies
  @cookies
end

#envObject

Returns the value of attribute env.



25
26
27
# File 'lib/action_controller/test_process.rb', line 25

def env
  @env
end

#hostObject

Returns the value of attribute host.



26
27
28
# File 'lib/action_controller/test_process.rb', line 26

def host
  @host
end

#pathObject

Returns the value of attribute path.



25
26
27
# File 'lib/action_controller/test_process.rb', line 25

def path
  @path
end

#query_parametersObject

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_parametersObject

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

#sessionObject

Returns the value of attribute session.



25
26
27
# File 'lib/action_controller/test_process.rb', line 25

def session
  @session
end

#session_optionsObject

Returns the value of attribute session_options.



24
25
26
# File 'lib/action_controller/test_process.rb', line 24

def session_options
  @session_options
end

#user_agentObject

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

#bodyObject

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_postObject

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

#refererObject



124
125
126
# File 'lib/action_controller/test_process.rb', line 124

def referer
  @env["HTTP_REFERER"]
end

#remote_addrObject



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_uriObject



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_sessionObject



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