2011-06-05 07:34:27 -04:00
|
|
|
require 'active_support/core_ext/hash/indifferent_access'
|
2011-03-06 07:49:44 -05:00
|
|
|
require 'rack/utils'
|
2010-03-28 08:15:02 -04:00
|
|
|
|
2009-04-30 18:26:03 -04:00
|
|
|
module ActionDispatch
|
|
|
|
class TestRequest < Request
|
2013-07-25 02:46:54 -04:00
|
|
|
DEFAULT_ENV = Rack::MockRequest.env_for('/',
|
|
|
|
'HTTP_HOST' => 'test.host',
|
|
|
|
'REMOTE_ADDR' => '0.0.0.0',
|
|
|
|
'HTTP_USER_AGENT' => 'Rails Testing'
|
|
|
|
)
|
2009-04-30 20:23:50 -04:00
|
|
|
|
2009-04-30 18:26:03 -04:00
|
|
|
def self.new(env = {})
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(env = {})
|
2012-05-21 15:24:18 -04:00
|
|
|
env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
|
2012-07-03 20:37:47 -04:00
|
|
|
super(default_env.merge(env))
|
2009-04-30 18:26:03 -04:00
|
|
|
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
|
|
|
|
|
2009-05-01 00:31:20 -04:00
|
|
|
def action=(action_name)
|
2014-07-02 02:42:41 -04:00
|
|
|
path_parameters[:action] = action_name.to_s
|
2009-05-01 00:31:20 -04:00
|
|
|
end
|
|
|
|
|
2009-04-30 18:26:03 -04:00
|
|
|
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)
|
2009-04-30 20:23:50 -04:00
|
|
|
@env.delete('action_dispatch.request.accepts')
|
2010-09-22 15:53:02 -04:00
|
|
|
@env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_type| mime_type.to_s }.join(",")
|
2009-04-30 18:26:03 -04:00
|
|
|
end
|
2011-06-05 07:34:27 -04:00
|
|
|
|
|
|
|
alias :rack_cookies :cookies
|
|
|
|
|
|
|
|
def cookies
|
|
|
|
@cookies ||= {}.with_indifferent_access
|
|
|
|
end
|
2012-07-03 20:37:47 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def default_env
|
|
|
|
DEFAULT_ENV
|
|
|
|
end
|
2009-04-30 18:26:03 -04:00
|
|
|
end
|
|
|
|
end
|