Class: ActionController::TestRequest

Inherits:
ActionDispatch::TestRequest show all
Defined in:
actionpack/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::ENV_METHODS, 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, extract_domain, extract_subdomain, extract_subdomains, #host, #host_with_port, #optional_port, #port, #port_string, #protocol, #raw_host_with_port, #server_port, #standard_port, #standard_port?, #subdomain, #subdomains, #url, url_for

Methods included from ActionDispatch::Http::FilterParameters

#filtered_env, #filtered_parameters, #filtered_path

Methods included from ActiveSupport::Concern

#append_features, extended, #included

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.



129
130
131
132
133
134
# File 'actionpack/lib/action_controller/test_case.rb', line 129

def initialize(env = {})
  super

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

Instance Method Details

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



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
174
175
# File 'actionpack/lib/action_controller/test_case.rb', line 143

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



177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'actionpack/lib/action_controller/test_case.rb', line 177

def recycle!
  write_cookies!
  @env.delete('HTTP_COOKIE') if @cookies.blank?
  @env.delete('action_dispatch.cookies')
  @cookies = nil
  @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 = @protocol = nil
  @env['action_dispatch.request.query_parameters'] = {}
end