Class: ActionController::TestRequest

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

Overview

:nodoc:

Constant Summary

Constants inherited from AbstractRequest

AbstractRequest::HTTP_METHODS, AbstractRequest::HTTP_METHOD_LOOKUP, AbstractRequest::TRUSTED_PROXIES

Instance Attribute Summary collapse

Attributes inherited from AbstractRequest

#env

Instance Method Summary collapse

Methods inherited from AbstractRequest

#accepts, #body, #cache_format, clean_up_ajax_request_body!, #content_length, #content_type, #delete?, #domain, #etag_matches?, extract_content_type_without_parameters, extract_multipart_boundary, #format, #format=, #fresh?, #get?, #head?, #headers, #host_with_port, #if_modified_since, #if_none_match, #method, #not_modified?, #parameters, parse_multipart_form_parameters, parse_query_parameters, parse_request_parameters, #path_parameters, #path_parameters=, #port, #port_string, #post?, #protocol, #put?, #query_string, #raw_host_with_port, #referrer, #relative_url_root, relative_url_root=, #remote_addr, #remote_ip, #request_method, #server_software, #ssl?, #standard_port, #subdomains, #symbolized_path_parameters, #template_format, #url, #xml_http_request?

Constructor Details

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

Returns a new instance of TestRequest.



36
37
38
39
40
41
42
43
44
45
# File 'lib/action_controller/test_process.rb', line 36

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.



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

def cookies
  @cookies
end

#hostObject

Returns the value of attribute host.



34
35
36
# File 'lib/action_controller/test_process.rb', line 34

def host
  @host
end

#path(*args) ⇒ Object

Returns the value of attribute path.



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

def path
  @path
end

#query_parametersObject

Returns the value of attribute query_parameters.



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

def query_parameters
  @query_parameters
end

#request_parametersObject

Returns the value of attribute request_parameters.



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

def request_parameters
  @request_parameters
end

#sessionObject

Returns the value of attribute session.



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

def session
  @session
end

#session_optionsObject

Returns the value of attribute session_options.



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

def session_options
  @session_options
end

#user_agentObject

Returns the value of attribute user_agent.



34
35
36
# File 'lib/action_controller/test_process.rb', line 34

def user_agent
  @user_agent
end

Instance Method Details

#accept=(mime_types) ⇒ Object



87
88
89
90
# File 'lib/action_controller/test_process.rb', line 87

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

#action=(action_name) ⇒ Object



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

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

#assign_parameters(controller_path, action, parameters) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/action_controller/test_process.rb', line 112

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_streamObject

Wraps raw_post in a StringIO.



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

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

#if_modified_since=(last_modified) ⇒ Object



92
93
94
# File 'lib/action_controller/test_process.rb', line 92

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

#if_none_match=(etag) ⇒ Object



96
97
98
# File 'lib/action_controller/test_process.rb', line 96

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

#port=(number) ⇒ Object



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

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

#raw_postObject

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



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

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



132
133
134
135
136
137
# File 'lib/action_controller/test_process.rb', line 132

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

#remote_addr=(addr) ⇒ Object



100
101
102
# File 'lib/action_controller/test_process.rb', line 100

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

#request_uri(*args) ⇒ Object



104
105
106
# File 'lib/action_controller/test_process.rb', line 104

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

#request_uri=(uri) ⇒ Object



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

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

#reset_sessionObject



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

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.



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

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