Class: ActionController::TestRequest
- Inherits:
-
ActionDispatch::TestRequest
- Object
- ActionDispatch::Request
- ActionDispatch::TestRequest
- ActionController::TestRequest
- Defined in:
- lib/action_controller/test_case.rb
Overview
ActionController::TestCase will be deprecated and moved to a gem in Rails 5.1. Please use ActionDispatch::IntegrationTest going forward.
Constant Summary collapse
- DEFAULT_ENV =
:nodoc:
ActionDispatch::TestRequest::DEFAULT_ENV.dup
- ENCODER =
Class.new do include Rack::Test::Utils def should_multipart?(params) # FIXME: lifted from Rack-Test. We should push this separation upstream multipart = false query = lambda { |value| case value when Array value.each(&query) when Hash value.values.each(&query) when Rack::Test::UploadedFile multipart = true end } params.values.each(&query) multipart end public :build_multipart def content_type "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}" end end.new
Constants inherited from ActionDispatch::Request
ActionDispatch::Request::ACTION_DISPATCH_REQUEST_ID, ActionDispatch::Request::ENV_METHODS, ActionDispatch::Request::HTTP_METHODS, ActionDispatch::Request::HTTP_METHOD_LOOKUP, ActionDispatch::Request::LOCALHOST, ActionDispatch::Request::PASS_NOT_FOUND, ActionDispatch::Request::RFC2518, ActionDispatch::Request::RFC2616, ActionDispatch::Request::RFC3253, ActionDispatch::Request::RFC3648, ActionDispatch::Request::RFC3744, ActionDispatch::Request::RFC4791, ActionDispatch::Request::RFC5323, ActionDispatch::Request::RFC5789
Constants included from ActionDispatch::Http::URL
ActionDispatch::Http::URL::HOST_REGEXP, ActionDispatch::Http::URL::IP_HOST_REGEXP, ActionDispatch::Http::URL::PROTOCOL_REGEXP
Constants included from ActionDispatch::Http::FilterParameters
ActionDispatch::Http::FilterParameters::ENV_MATCH, ActionDispatch::Http::FilterParameters::NULL_ENV_FILTER, ActionDispatch::Http::FilterParameters::NULL_PARAM_FILTER
Constants included from ActionDispatch::Http::Parameters
ActionDispatch::Http::Parameters::DEFAULT_PARSERS, ActionDispatch::Http::Parameters::PARAMETERS_KEY
Constants included from ActionDispatch::Http::Cache::Request
ActionDispatch::Http::Cache::Request::HTTP_IF_MODIFIED_SINCE, ActionDispatch::Http::Cache::Request::HTTP_IF_NONE_MATCH
Class Method Summary collapse
-
.create ⇒ Object
Create a new test request with default ‘env` values.
- .new_session ⇒ Object
Instance Method Summary collapse
- #assign_parameters(routes, controller_path, action, parameters, generated_path, query_string_keys) ⇒ Object
- #content_type=(type) ⇒ Object
-
#initialize(env, session) ⇒ TestRequest
constructor
A new instance of TestRequest.
- #query_string=(string) ⇒ Object
Methods inherited from ActionDispatch::TestRequest
#accept=, #action=, #host=, #if_modified_since=, #if_none_match=, #path=, #port=, #remote_addr=, #request_method=, #request_uri=, #user_agent=
Methods inherited from ActionDispatch::Request
#GET, #POST, #authorization, #body, #body_stream, #check_path_parameters!, #commit_cookie_jar!, #commit_flash, #content_length, #controller_class, #controller_instance, #controller_instance=, #cookie_jar, #cookie_jar=, #cookies_digest, #cookies_serializer, empty, #encrypted_cookie_salt, #encrypted_signed_cookie_salt, #engine_script_name, #engine_script_name=, #form_data?, #fullpath, #have_cookie_jar?, #headers, #http_auth_salt, #ip, #key?, #key_generator, #local?, #logger, #media_type, #method, #method_symbol, #original_fullpath, #original_url, #raw_post, #remote_ip, #remote_ip=, #request_id, #request_id=, #request_method, #request_method=, #request_method_symbol, #request_parameters=, #reset_session, #routes, #routes=, #secret_key_base, #secret_token, #server_software, #session=, #session_options=, #show_exceptions?, #signed_cookie_salt, #ssl?, #xml_http_request?
Methods included from ActionDispatch::Http::URL
#domain, extract_domain, extract_subdomain, extract_subdomains, full_url_for, #host, #host_with_port, #optional_port, path_for, #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 ActionDispatch::Http::Parameters
#parameters, #path_parameters, #path_parameters=
Methods included from ActionDispatch::Http::MimeNegotiation
#accepts, #content_mime_type, #content_type, #format, #format=, #formats, #formats=, #has_content_type?, #negotiate_mime, #variant, #variant=
Methods included from ActionDispatch::Http::Cache::Request
#etag_matches?, #fresh?, #if_modified_since, #if_none_match, #if_none_match_etags, #not_modified?
Methods included from ActionDispatch::Flash::RequestMethods
#commit_flash, #flash, #flash=, #flash_hash, #reset_session
Constructor Details
#initialize(env, session) ⇒ TestRequest
Returns a new instance of TestRequest.
49 50 51 52 53 54 55 56 57 |
# File 'lib/action_controller/test_case.rb', line 49 def initialize(env, session) super(env) self.session = session self. = TestSession::DEFAULT_OPTIONS @custom_param_parsers = { xml: lambda { |raw_post| Hash.from_xml(raw_post)['hash'] } } end |
Class Method Details
.create ⇒ Object
Create a new test request with default ‘env` values
37 38 39 40 41 42 |
# File 'lib/action_controller/test_case.rb', line 37 def self.create env = {} env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application env["rack.request.cookie_hash"] = {}.with_indifferent_access new(default_env.merge(env), new_session) end |
.new_session ⇒ Object
32 33 34 |
# File 'lib/action_controller/test_case.rb', line 32 def self.new_session TestSession.new end |
Instance Method Details
#assign_parameters(routes, controller_path, action, parameters, generated_path, query_string_keys) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/action_controller/test_case.rb', line 67 def assign_parameters(routes, controller_path, action, parameters, generated_path, query_string_keys) non_path_parameters = {} path_parameters = {} parameters.each do |key, value| if query_string_keys.include?(key) non_path_parameters[key] = value else if value.is_a?(Array) value = value.map(&:to_param) else value = value.to_param end path_parameters[key] = value end end if get? if self.query_string.blank? self.query_string = non_path_parameters.to_query end else if ENCODER.should_multipart?(non_path_parameters) self.content_type = ENCODER.content_type data = ENCODER.build_multipart non_path_parameters else fetch_header('CONTENT_TYPE') do |k| set_header k, 'application/x-www-form-urlencoded' end case content_mime_type.to_sym when nil raise "Unknown Content-Type: #{content_type}" when :json data = ActiveSupport::JSON.encode(non_path_parameters) when :xml data = non_path_parameters.to_xml when :url_encoded_form data = non_path_parameters.to_query else @custom_param_parsers[content_mime_type.symbol] = ->(_) { non_path_parameters } data = non_path_parameters.to_query end end set_header 'CONTENT_LENGTH', data.length.to_s set_header 'rack.input', StringIO.new(data) end fetch_header("PATH_INFO") do |k| set_header k, generated_path end path_parameters[:controller] = controller_path path_parameters[:action] = action self.path_parameters = path_parameters end |
#content_type=(type) ⇒ Object
63 64 65 |
# File 'lib/action_controller/test_case.rb', line 63 def content_type=(type) set_header 'CONTENT_TYPE', type end |
#query_string=(string) ⇒ Object
59 60 61 |
# File 'lib/action_controller/test_case.rb', line 59 def query_string=(string) set_header Rack::QUERY_STRING, string end |