2009-04-30 18:26:03 -04:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
class TestRequestTest < ActiveSupport::TestCase
|
|
|
|
test "sane defaults" do
|
|
|
|
env = ActionDispatch::TestRequest.new.env
|
|
|
|
|
|
|
|
assert_equal "GET", env.delete("REQUEST_METHOD")
|
2009-09-01 00:08:20 -04:00
|
|
|
assert_equal nil, env.delete("HTTPS")
|
2009-04-30 18:26:03 -04:00
|
|
|
assert_equal "http", env.delete("rack.url_scheme")
|
|
|
|
assert_equal "example.org", env.delete("SERVER_NAME")
|
|
|
|
assert_equal "80", env.delete("SERVER_PORT")
|
|
|
|
assert_equal "/", env.delete("PATH_INFO")
|
|
|
|
assert_equal "", env.delete("SCRIPT_NAME")
|
|
|
|
assert_equal "", env.delete("QUERY_STRING")
|
|
|
|
assert_equal "0", env.delete("CONTENT_LENGTH")
|
|
|
|
|
|
|
|
assert_equal "test.host", env.delete("HTTP_HOST")
|
|
|
|
assert_equal "0.0.0.0", env.delete("REMOTE_ADDR")
|
|
|
|
assert_equal "Rails Testing", env.delete("HTTP_USER_AGENT")
|
|
|
|
|
2009-09-01 00:08:20 -04:00
|
|
|
assert_equal [0, 1], env.delete("rack.version")
|
2009-04-30 18:26:03 -04:00
|
|
|
assert_equal "", env.delete("rack.input").string
|
|
|
|
assert_kind_of StringIO, env.delete("rack.errors")
|
|
|
|
assert_equal true, env.delete("rack.multithread")
|
|
|
|
assert_equal true, env.delete("rack.multiprocess")
|
|
|
|
assert_equal false, env.delete("rack.run_once")
|
|
|
|
|
|
|
|
assert env.empty?, env.inspect
|
|
|
|
end
|
2009-04-30 20:23:50 -04:00
|
|
|
|
|
|
|
test "cookie jar" do
|
|
|
|
req = ActionDispatch::TestRequest.new
|
|
|
|
|
|
|
|
assert_equal({}, req.cookies)
|
|
|
|
assert_equal nil, req.env["HTTP_COOKIE"]
|
|
|
|
|
|
|
|
req.cookies["user_name"] = "david"
|
|
|
|
assert_equal({"user_name" => "david"}, req.cookies)
|
|
|
|
assert_equal "user_name=david;", req.env["HTTP_COOKIE"]
|
|
|
|
|
|
|
|
req.cookies["login"] = "XJ-122"
|
|
|
|
assert_equal({"user_name" => "david", "login" => "XJ-122"}, req.cookies)
|
2009-05-02 18:30:00 -04:00
|
|
|
assert_equal %w(login=XJ-122 user_name=david), req.env["HTTP_COOKIE"].split(/; ?/).sort
|
2009-04-30 20:23:50 -04:00
|
|
|
end
|
2009-04-30 18:26:03 -04:00
|
|
|
end
|