Class: ActionController::TestRequest

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

Overview

:nodoc:

Constant Summary

Constants inherited from Request

Request::HTTP_METHODS, Request::HTTP_METHOD_LOOKUP, Request::TRUSTED_PROXIES

Constants inherited from Rack::Request

Rack::Request::FORM_DATA_MEDIA_TYPES

Instance Attribute Summary collapse

Attributes inherited from Rack::Request

#env

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Request

#GET, #POST, #accepts, #body, #cache_format, #content_length, #content_type, #delete?, #domain, #etag_matches?, #form_data?, #format, #format=, #fresh?, #get?, #head?, #headers, #host_with_port, #if_modified_since, #if_none_match, #key?, #method, #not_modified?, #parameters, #path_parameters, #path_parameters=, #port, #port_string, #post?, #protocol, #put?, #query_string, #raw_host_with_port, #remote_ip, #request_method, #server_port, #server_software, #ssl?, #standard_port, #subdomains, #symbolized_path_parameters, #template_format, #url, #xml_http_request?

Methods inherited from Rack::Request

#GET, #POST, #[], #[]=, #accept_encoding, #body, #content_charset, #content_length, #content_type, #delete?, #form_data?, #fullpath, #get?, #head?, #ip, #media_type, #media_type_params, #openid_request, #openid_response, #params, #path_info, #path_info=, #port, #post?, #put?, #query_string, #referer, #request_method, #scheme, #script_name, #script_name=, #url, #values_at, #xhr?

Constructor Details

#initialize(env = {}) ⇒ TestRequest

Returns a new instance of TestRequest.



11
12
13
14
15
16
17
18
19
# File 'lib/action_controller/test_process.rb', line 11

def initialize(env = {})
  super(Rack::MockRequest.env_for("/").merge(env))

  @query_parameters   = {}
  @session            = TestSession.new

  initialize_default_values
  initialize_containers
end

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies.



3
4
5
# File 'lib/action_controller/test_process.rb', line 3

def cookies
  @cookies
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/action_controller/test_process.rb', line 5

def host
  @host
end

#path(*args) ⇒ Object

Returns the value of attribute path.



4
5
6
# File 'lib/action_controller/test_process.rb', line 4

def path
  @path
end

#query_parametersObject

Returns the value of attribute query_parameters.



4
5
6
# File 'lib/action_controller/test_process.rb', line 4

def query_parameters
  @query_parameters
end

#sessionObject

Returns the value of attribute session.



4
5
6
# File 'lib/action_controller/test_process.rb', line 4

def session
  @session
end

#session_optionsObject

Returns the value of attribute session_options.



3
4
5
# File 'lib/action_controller/test_process.rb', line 3

def session_options
  @session_options
end

Class Method Details

.new(env = {}) ⇒ Object



7
8
9
# File 'lib/action_controller/test_process.rb', line 7

def self.new(env = {})
  super
end

Instance Method Details

#accept=(mime_types) ⇒ Object



66
67
68
69
# File 'lib/action_controller/test_process.rb', line 66

def accept=(mime_types)
  @env["HTTP_ACCEPT"] = Array(mime_types).collect { |mime_types| mime_types.to_s }.join(",")
  @accepts = nil
end

#action=(action_name) ⇒ Object



44
45
46
47
# File 'lib/action_controller/test_process.rb', line 44

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

#assign_parameters(controller_path, action, parameters) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/action_controller/test_process.rb', line 91

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
  raw_post # populate env['RAW_POST_DATA']
  @parameters = nil # reset TestRequest#parameters to use the new path_parameters
end

#body_streamObject

Wraps raw_post in a StringIO.



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

def body_stream #:nodoc:
  StringIO.new(raw_post)
end

#if_modified_since=(last_modified) ⇒ Object



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

def if_modified_since=(last_modified)
  @env["HTTP_IF_MODIFIED_SINCE"] = last_modified
end

#if_none_match=(etag) ⇒ Object



75
76
77
# File 'lib/action_controller/test_process.rb', line 75

def if_none_match=(etag)
  @env["HTTP_IF_NONE_MATCH"] = etag
end

#port=(number) ⇒ Object



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

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

#raw_postObject

Either the RAW_POST_DATA environment variable or the URL-encoded request parameters.



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

def raw_post
  @env['RAW_POST_DATA'] ||= begin
    data = url_encoded_request_parameters
    data.force_encoding(Encoding::BINARY) if data.respond_to?(:force_encoding)
    data
  end
end

#recycle!Object



112
113
114
115
116
# File 'lib/action_controller/test_process.rb', line 112

def recycle!
  self.query_parameters   = {}
  self.path_parameters    = {}
  @headers, @request_method, @accepts, @content_type = nil, nil, nil, nil
end

#remote_addr=(addr) ⇒ Object



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

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

#request_method=(method) ⇒ Object



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

def request_method=(method)
  @request_method = method
end

#request_uri(*args) ⇒ Object



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

def request_uri(*args)
  @request_uri || super()
end

#request_uri=(uri) ⇒ Object



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

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

#reset_sessionObject



21
22
23
# File 'lib/action_controller/test_process.rb', line 21

def reset_session
  @session.reset
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.



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

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

#user_agent=(user_agent) ⇒ Object



118
119
120
# File 'lib/action_controller/test_process.rb', line 118

def user_agent=(user_agent)
  @env['HTTP_USER_AGENT'] = user_agent
end