class ActionController::TestRequest
:nodoc:
Please use ActionDispatch::IntegrationTest going forward.
ActionController::TestCase will be deprecated and moved to a gem in the future.
def self.create(controller_class)
def self.create(controller_class) 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, controller_class) end
def self.default_env
def self.default_env DEFAULT_ENV end
def self.new_session
def self.new_session TestSession.new end
def assign_parameters(routes, controller_path, action, parameters, generated_path, query_string_keys)
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.to_sym] = value end end if get? if 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 data_stream = StringIO.new(data) set_header "CONTENT_LENGTH", data_stream.length.to_s set_header "rack.input", data_stream 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
def content_type=(type)
def content_type=(type) set_header "CONTENT_TYPE", type end
def initialize(env, session, controller_class)
def initialize(env, session, controller_class) super(env) self.session = session self.session_options = TestSession::DEFAULT_OPTIONS.dup @controller_class = controller_class @custom_param_parsers = { xml: lambda { |raw_post| Hash.from_xml(raw_post)["hash"] } } end
def params_parsers
def params_parsers super.merge @custom_param_parsers end
def query_string=(string)
def query_string=(string) set_header Rack::QUERY_STRING, string end