Sha256: 9cfb7189bdedda1d11a6669aacd75e26476a009c58cc7532067c9630cd5f29b9

Contents?: true

Size: 1.7 KB

Versions: 16

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

require "active_support/core_ext/hash/indifferent_access"
require "rack/utils"

module ActionDispatch
  class TestRequest < Request
    DEFAULT_ENV = Rack::MockRequest.env_for("/",
      "HTTP_HOST"                => "test.host".b,
      "REMOTE_ADDR"              => "0.0.0.0".b,
      "HTTP_USER_AGENT"          => "Rails Testing".b,
    )

    # Create a new test request with default +env+ values.
    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))
    end

    def self.default_env
      DEFAULT_ENV
    end
    private_class_method :default_env

    def request_method=(method)
      super(method.to_s.upcase)
    end

    def host=(host)
      set_header("HTTP_HOST", host)
    end

    def port=(number)
      set_header("SERVER_PORT", number)
    end

    def request_uri=(uri)
      set_header("REQUEST_URI", uri)
    end

    def path=(path)
      set_header("PATH_INFO", path)
    end

    def action=(action_name)
      path_parameters[:action] = action_name.to_s
    end

    def if_modified_since=(last_modified)
      set_header("HTTP_IF_MODIFIED_SINCE", last_modified)
    end

    def if_none_match=(etag)
      set_header("HTTP_IF_NONE_MATCH", etag)
    end

    def remote_addr=(addr)
      set_header("REMOTE_ADDR", addr)
    end

    def user_agent=(user_agent)
      set_header("HTTP_USER_AGENT", user_agent)
    end

    def accept=(mime_types)
      delete_header("action_dispatch.request.accepts")
      set_header("HTTP_ACCEPT", Array(mime_types).collect(&:to_s).join(","))
    end
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
actionpack-7.1.5 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.4.2 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.4.1 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.4 lib/action_dispatch/testing/test_request.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actionpack-7.1.3.4/lib/action_dispatch/testing/test_request.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/actionpack-7.1.3.4/lib/action_dispatch/testing/test_request.rb
actionpack-7.1.3.4 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.3.2 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.3.1 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.3 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.2 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.1 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.0 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.0.rc2 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.0.rc1 lib/action_dispatch/testing/test_request.rb
actionpack-7.1.0.beta1 lib/action_dispatch/testing/test_request.rb