Sha256: 971782fcfb1afa3307e478d8f5c959418a312063e6146d2ee2ba5d5e50f3080b

Contents?: true

Size: 1.63 KB

Versions: 52

Compression:

Stored size: 1.63 KB

Contents

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',
      'REMOTE_ADDR'     => '0.0.0.0',
      'HTTP_USER_AGENT' => 'Rails Testing'
    )

    def self.new(env = {})
      super
    end

    def initialize(env = {})
      env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
      super(default_env.merge(env))
    end

    def request_method=(method)
      @env['REQUEST_METHOD'] = method.to_s.upcase
    end

    def host=(host)
      @env['HTTP_HOST'] = host
    end

    def port=(number)
      @env['SERVER_PORT'] = number.to_i
    end

    def request_uri=(uri)
      @env['REQUEST_URI'] = uri
    end

    def path=(path)
      @env['PATH_INFO'] = path
    end

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

    def if_modified_since=(last_modified)
      @env['HTTP_IF_MODIFIED_SINCE'] = last_modified
    end

    def if_none_match=(etag)
      @env['HTTP_IF_NONE_MATCH'] = etag
    end

    def remote_addr=(addr)
      @env['REMOTE_ADDR'] = addr
    end

    def user_agent=(user_agent)
      @env['HTTP_USER_AGENT'] = user_agent
    end

    def accept=(mime_types)
      @env.delete('action_dispatch.request.accepts')
      @env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_type| mime_type.to_s }.join(",")
    end

    alias :rack_cookies :cookies

    def cookies
      @cookies ||= {}.with_indifferent_access
    end

    private

    def default_env
      DEFAULT_ENV
    end
  end
end

Version data entries

52 entries across 51 versions & 8 rubygems

Version Path
actionpack-4.2.11.3 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.11.2 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.11.1 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.11 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.10 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.10.rc1 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.9 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.9.rc2 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.9.rc1 lib/action_dispatch/testing/test_request.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/actionpack-4.2.8/lib/action_dispatch/testing/test_request.rb
actionpack-4.2.8 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.8.rc1 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.7.1 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.7 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.7.rc1 lib/action_dispatch/testing/test_request.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/testing/test_request.rb
actionpack-4.2.6 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.6.rc1 lib/action_dispatch/testing/test_request.rb
actionpack-4.2.5.2 lib/action_dispatch/testing/test_request.rb
activejob-lock-0.0.2 rails/actionpack/lib/action_dispatch/testing/test_request.rb