Class: ActionController::TestRequest

Inherits:
ActionDispatch::TestRequest show all
Defined in:
lib/action_controller/test_case.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Result

Constant Summary

Constants inherited from ActionDispatch::TestRequest

ActionDispatch::TestRequest::DEFAULT_ENV

Constants inherited from ActionDispatch::Request

ActionDispatch::Request::HTTP_METHODS, ActionDispatch::Request::HTTP_METHOD_LOOKUP, ActionDispatch::Request::LOCALHOST, ActionDispatch::Request::RFC2518, ActionDispatch::Request::RFC2616, ActionDispatch::Request::RFC3253, ActionDispatch::Request::RFC3648, ActionDispatch::Request::RFC3744, ActionDispatch::Request::RFC5323, ActionDispatch::Request::RFC5789, ActionDispatch::Request::TRUSTED_PROXIES

Instance Method Summary collapse

Methods inherited from ActionDispatch::TestRequest

#accept=, #action=, #cookies, #env, #host=, #if_modified_since=, #if_none_match=, new, #path=, #port=, #remote_addr=, #request_method=, #request_uri=, #user_agent=

Methods inherited from ActionDispatch::Request

#GET, #POST, #authorization, #body, #body_stream, #content_length, #cookie_jar, #delete?, #flash, #forgery_whitelisted?, #form_data?, #fullpath, #get?, #head?, #headers, #ip, #key?, #local?, #media_type, #method, #method_symbol, new, #post?, #put?, #raw_post, #remote_ip, #request_method, #request_method_symbol, #reset_session, #server_software, #session=, #session_options=, #xml_http_request?

Methods included from ActionDispatch::Http::URL

#domain, #host, #host_with_port, #port, #port_string, #protocol, #raw_host_with_port, #request_uri, #scheme, #server_port, #ssl?, #standard_port, #standard_port?, #subdomain, #subdomains, #url

Methods included from ActionDispatch::Http::FilterParameters

#filtered_env, #filtered_parameters, #filtered_path

Methods included from ActionDispatch::Http::Parameters

#parameters, #path_parameters, #path_parameters=, #symbolized_path_parameters

Methods included from ActionDispatch::Http::MimeNegotiation

#accepts, #content_mime_type, #content_type, #format, #format=, #formats, #negotiate_mime

Methods included from ActionDispatch::Http::Cache::Request

#etag_matches?, #fresh?, #if_modified_since, #if_none_match, #not_modified?

Constructor Details

#initialize(env = {}) ⇒ TestRequest

Returns a new instance of TestRequest.



127
128
129
130
131
132
# File 'lib/action_controller/test_case.rb', line 127

def initialize(env = {})
  super

  self.session = TestSession.new
  self.session_options = TestSession::DEFAULT_OPTIONS.merge(:id => ActiveSupport::SecureRandom.hex(16))
end

Instance Method Details

#assign_parameters(routes, controller_path, action, parameters = {}) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/action_controller/test_case.rb', line 141

def assign_parameters(routes, controller_path, action, parameters = {})
  parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action)
  extra_keys = 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 = Result.new(value.map { |v| v.is_a?(String) ? v.dup : v })
    elsif value.is_a? String
      value = value.dup
    end

    if extra_keys.include?(key.to_sym)
      non_path_parameters[key] = value
    else
      path_parameters[key.to_s] = value
    end
  end

  # Clear the combined params hash in case it was already referenced.
  @env.delete("action_dispatch.request.parameters")

  params = self.request_parameters.dup
  %w(controller action only_path).each do |k|
    params.delete(k)
    params.delete(k.to_sym)
  end
  data = params.to_query

  @env['CONTENT_LENGTH'] = data.length.to_s
  @env['rack.input'] = StringIO.new(data)
end

#recycle!Object



175
176
177
178
179
180
181
182
183
# File 'lib/action_controller/test_case.rb', line 175

def recycle!
  @formats = nil
  @env.delete_if { |k, v| k =~ /^(action_dispatch|rack)\.request/ }
  @env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ }
  @symbolized_path_params = nil
  @method = @request_method = nil
  @fullpath = @ip = @remote_ip = nil
  @env['action_dispatch.request.query_parameters'] = {}
end