2009-04-30 18:26:03 -04:00
|
|
|
module ActionDispatch
|
|
|
|
class TestRequest < Request
|
2009-04-30 20:23:50 -04:00
|
|
|
DEFAULT_ENV = Rack::MockRequest.env_for('/')
|
|
|
|
|
2009-04-30 18:26:03 -04:00
|
|
|
def self.new(env = {})
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(env = {})
|
2009-04-30 20:23:50 -04:00
|
|
|
super(DEFAULT_ENV.merge(env))
|
2009-04-30 18:26:03 -04:00
|
|
|
|
|
|
|
self.host = 'test.host'
|
|
|
|
self.remote_addr = '0.0.0.0'
|
|
|
|
self.user_agent = 'Rails Testing'
|
|
|
|
end
|
|
|
|
|
2009-04-30 20:23:50 -04:00
|
|
|
def env
|
|
|
|
write_cookies!
|
2009-05-02 16:29:18 -04:00
|
|
|
delete_nil_values!
|
2009-04-30 20:23:50 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-04-30 18:26:03 -04:00
|
|
|
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)
|
|
|
|
path_parameters["action"] = action_name.to_s
|
|
|
|
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')
|
|
|
|
@env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_types| mime_types.to_s }.join(",")
|
2009-04-30 18:26:03 -04:00
|
|
|
end
|
2009-04-30 20:23:50 -04:00
|
|
|
|
|
|
|
def cookies
|
|
|
|
@cookies ||= super
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def write_cookies!
|
|
|
|
unless @cookies.blank?
|
|
|
|
@env['HTTP_COOKIE'] = @cookies.map { |name, value| "#{name}=#{value};" }.join(' ')
|
|
|
|
end
|
|
|
|
end
|
2009-05-02 16:29:18 -04:00
|
|
|
|
|
|
|
def delete_nil_values!
|
|
|
|
@env.delete_if { |k, v| v.nil? }
|
|
|
|
end
|
2009-04-30 18:26:03 -04:00
|
|
|
end
|
|
|
|
end
|