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

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::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

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



120
121
122
123
124
125
# File 'actionpack/lib/action_controller/test_case.rb', line 120

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



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'actionpack/lib/action_controller/test_case.rb', line 134

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)
    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



166
167
168
169
170
171
172
173
174
# File 'actionpack/lib/action_controller/test_case.rb', line 166

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