Class: ActionController::TestRequest

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractRequest

#delete?, #domain, #formatted_post?, #get?, #head?, #host_with_port, #method, #parameters, #path_parameters, #path_parameters=, #port, #port_string, #post?, #post_format, #protocol, #put?, #raw_post, #relative_url_root, #remote_ip, #server_software, #ssl?, #subdomains, #symbolized_path_parameters, #xml_http_request?, #xml_post?, #yaml_post?

Constructor Details

#initialize(query_parameters = nil, request_parameters = nil, session = nil) ⇒ TestRequest

Returns a new instance of TestRequest.



21
22
23
24
25
26
27
28
29
30
# File 'lib/action_controller/test_process.rb', line 21

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.



17
18
19
# File 'lib/action_controller/test_process.rb', line 17

def cookies
  @cookies
end

#envObject

Returns the value of attribute env.



18
19
20
# File 'lib/action_controller/test_process.rb', line 18

def env
  @env
end

#hostObject

Returns the value of attribute host.



19
20
21
# File 'lib/action_controller/test_process.rb', line 19

def host
  @host
end

#pathObject

Returns the value of attribute path.



18
19
20
# File 'lib/action_controller/test_process.rb', line 18

def path
  @path
end

#query_parametersObject

Returns the value of attribute query_parameters.



18
19
20
# File 'lib/action_controller/test_process.rb', line 18

def query_parameters
  @query_parameters
end

#request_parametersObject

Returns the value of attribute request_parameters.



18
19
20
# File 'lib/action_controller/test_process.rb', line 18

def request_parameters
  @request_parameters
end

#sessionObject

Returns the value of attribute session.



18
19
20
# File 'lib/action_controller/test_process.rb', line 18

def session
  @session
end

Instance Method Details

#action=(action_name) ⇒ Object



40
41
42
43
# File 'lib/action_controller/test_process.rb', line 40

def action=(action_name)
  @query_parameters.update({ "action" => action_name })
  @parameters = nil
end

#assign_parameters(controller_path, action, parameters) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/action_controller/test_process.rb', line 70

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 extra_keys.include?(key.to_sym)
      non_path_parameters[key] = value
    else
      path_parameters[key] = value.to_s
    end
  end
end

#port=(number) ⇒ Object



36
37
38
# File 'lib/action_controller/test_process.rb', line 36

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

#recycle!Object



83
84
85
86
87
# File 'lib/action_controller/test_process.rb', line 83

def recycle!
  self.request_parameters = {}
  self.query_parameters   = {}         
  self.path_parameters    = {}     
end

#remote_addr=(addr) ⇒ Object



58
59
60
# File 'lib/action_controller/test_process.rb', line 58

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

#request_uriObject



62
63
64
# File 'lib/action_controller/test_process.rb', line 62

def request_uri
  @request_uri || super()
end

#request_uri=(uri) ⇒ Object



53
54
55
56
# File 'lib/action_controller/test_process.rb', line 53

def request_uri=(uri)
  @request_uri = uri
  @path = uri.split("?").first
end

#reset_sessionObject



32
33
34
# File 'lib/action_controller/test_process.rb', line 32

def reset_session
  @session = {}
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.



47
48
49
50
51
# File 'lib/action_controller/test_process.rb', line 47

def set_REQUEST_URI(value)
  @env["REQUEST_URI"] = value
  @request_uri = nil
  @path = nil
end