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

#accepts, #content_type, #delete?, #domain, #formatted_post?, #get?, #head?, #host_with_port, #method, #parameters, #path_parameters, #path_parameters=, #port, #port_string, #post?, #post_format, #protocol, #put?, #relative_url_root, #remote_ip, #server_software, #ssl?, #standard_port, #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.



30
31
32
33
34
35
36
37
38
39
# File 'lib/action_controller/test_process.rb', line 30

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.



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

def cookies
  @cookies
end

#envObject

Returns the value of attribute env.



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

def env
  @env
end

#hostObject

Returns the value of attribute host.



28
29
30
# File 'lib/action_controller/test_process.rb', line 28

def host
  @host
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#query_parametersObject

Returns the value of attribute query_parameters.



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

def query_parameters
  @query_parameters
end

#request_parametersObject

Returns the value of attribute request_parameters.



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

def request_parameters
  @request_parameters
end

#sessionObject

Returns the value of attribute session.



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

def session
  @session
end

#session_optionsObject

Returns the value of attribute session_options.



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

def session_options
  @session_options
end

Instance Method Details

#action=(action_name) ⇒ Object



64
65
66
67
# File 'lib/action_controller/test_process.rb', line 64

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
# 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::PathComponent::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
end

#port=(number) ⇒ Object



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

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

#raw_postObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/action_controller/test_process.rb', line 45

def raw_post
  if raw_post = env['RAW_POST_DATA']
    raw_post
  else
    params = self.request_parameters.dup
    %w(controller action only_path).each do |k|
      params.delete(k)
      params.delete(k.to_sym)
    end

    params.map { |k,v| [ CGI.escape(k.to_s), CGI.escape(v.to_s) ].join('=') }.sort.join('&')
  end
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

#remote_addrObject



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_uriObject



90
91
92
# File 'lib/action_controller/test_process.rb', line 90

def request_uri
  @request_uri || super()
end

#request_uri=(uri) ⇒ Object



77
78
79
80
# File 'lib/action_controller/test_process.rb', line 77

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

#reset_sessionObject



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

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.



71
72
73
74
75
# File 'lib/action_controller/test_process.rb', line 71

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