test/aitch/request_test.rb in aitch-1.2.1 vs test/aitch/request_test.rb in aitch-1.2.2
- old
+ new
@@ -3,10 +3,11 @@
require "test_helper"
class RequestTest < Minitest::Test
test "sets content type" do
request = build_request(content_type: "application/json")
+
assert_equal "application/json", request.content_type
end
test "raises with invalid uri" do
assert_raises(Aitch::InvalidURIError) { build_request(url: "\\").uri }
@@ -33,30 +34,35 @@
assert_equal "CUSTOM", request["User-Agent"]
end
test "requests gzip encoding" do
request = build_request.request
+
assert_equal "gzip,deflate", request["Accept-Encoding"]
end
test "sets path" do
request = build_request(url: "http://example.org/some/path").request
+
assert_equal "/some/path", request.path
end
test "sets request body from hash" do
request = build_request(request_method: "post", data: {a: 1}).request
+
assert_equal "a=1", request.body
end
test "sets request body from string" do
request = build_request(request_method: "post", data: "some body").request
+
assert_equal "some body", request.body
end
test "sets request body from params key" do
request = build_request(request_method: "post", params: "some body").request
+
assert_equal "some body", request.body
end
test "sets json body from object" do
request = build_request(
@@ -65,10 +71,11 @@
content_type: "application/json",
options: {json_parser: JSON}
).request
expected = {a: 1}.to_json
+
assert_equal expected, request.body
end
test "sets json body from object (default headers)" do
request = build_request(
@@ -76,16 +83,18 @@
data: {a: 1},
options: {json_parser: JSON, default_headers: {"Content-Type" => "application/json"}}
).request
expected = {a: 1}.to_json
+
assert_equal expected, request.body
end
test "sets request body from to_h protocol" do
data = stub(to_h: {a: 1})
request = build_request(request_method: "post", data: data).request
+
assert_equal "a=1", request.body
end
test "sets json body from array" do
data = [1, 2, 3]
@@ -121,14 +130,22 @@
assert_equal "VALUE", request["HEADER"]
end
test "sets custom headers" do
request = build_request(headers: {"HEADER" => "VALUE"}).request
+
assert_equal "VALUE", request["HEADER"]
end
+ test "sets headers from underscored headers" do
+ request = build_request(headers: {content_type: "text/plain"}).request
+
+ assert_equal "text/plain", request["Content-Type"]
+ end
+
test "executes headers with callable protocol" do
request = build_request(headers: {"HEADER" => -> { "VALUE" }}).request
+
assert_equal "VALUE", request["HEADER"]
end
test "sets basic auth credentials" do
request = build_request(options: {user: "USER", password: "PASS"}).request