active_rest_client 0.9.70 → 0.9.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_rest_client/connection.rb +4 -4
- data/lib/active_rest_client/version.rb +1 -1
- data/spec/lib/connection_spec.rb +53 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b3b9e60fbe7fcac66d2abb8fdfca13ffc67a4af
|
4
|
+
data.tar.gz: 7193b387bb571a86de67db438a993357571490d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1fcb9dd01cc0a5bd476fcb1733a421ee8a490e94bb695593469c1cfc9675a5285ad43f946b557d6ec064d5dc2d1f643504cbae03b45fa88b12a2bc823515f58
|
7
|
+
data.tar.gz: 1ce2d5a2bcbe5ff8ffd2ea4fcace14f25c98c234b5c8cfffd90828b4304a3e365611986994607e6412ebd70313ea7737ad539d18ea4dca638f3fd5db726b35e9
|
@@ -37,7 +37,7 @@ module ActiveRestClient
|
|
37
37
|
def get(path, headers={})
|
38
38
|
make_safe_request(path) do
|
39
39
|
@session.get(path) do |req|
|
40
|
-
req.headers = headers
|
40
|
+
req.headers = req.headers.merge(headers)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -45,7 +45,7 @@ module ActiveRestClient
|
|
45
45
|
def put(path, data, headers={})
|
46
46
|
make_safe_request(path) do
|
47
47
|
@session.put(path) do |req|
|
48
|
-
req.headers = headers
|
48
|
+
req.headers = req.headers.merge(headers)
|
49
49
|
req.body = data
|
50
50
|
end
|
51
51
|
end
|
@@ -54,7 +54,7 @@ module ActiveRestClient
|
|
54
54
|
def post(path, data, headers={})
|
55
55
|
make_safe_request(path) do
|
56
56
|
@session.post(path) do |req|
|
57
|
-
req.headers = headers
|
57
|
+
req.headers = req.headers.merge(headers)
|
58
58
|
req.body = data
|
59
59
|
end
|
60
60
|
end
|
@@ -63,7 +63,7 @@ module ActiveRestClient
|
|
63
63
|
def delete(path, headers={})
|
64
64
|
make_safe_request(path) do
|
65
65
|
@session.delete(path) do |req|
|
66
|
-
req.headers = headers
|
66
|
+
req.headers = req.headers.merge(headers)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
data/spec/lib/connection_spec.rb
CHANGED
@@ -5,6 +5,11 @@ describe ActiveRestClient::Connection do
|
|
5
5
|
@connection = ActiveRestClient::Connection.new("http://www.example.com")
|
6
6
|
end
|
7
7
|
|
8
|
+
after do
|
9
|
+
ActiveRestClient::Base._reset_configuration!
|
10
|
+
@connection.reconnect
|
11
|
+
end
|
12
|
+
|
8
13
|
it "should contain a Farday connection" do
|
9
14
|
expect(@connection.session).to be_a_kind_of(Faraday::Connection)
|
10
15
|
end
|
@@ -45,6 +50,54 @@ describe ActiveRestClient::Connection do
|
|
45
50
|
expect(result.body).to eq("{result:true}")
|
46
51
|
end
|
47
52
|
|
53
|
+
describe "with default Faraday headers" do
|
54
|
+
before do
|
55
|
+
@default_headers = { "User-Agent" => "Custom" }
|
56
|
+
|
57
|
+
ActiveRestClient::Base.faraday_config do |faraday|
|
58
|
+
faraday.adapter ActiveRestClient::Base.adapter
|
59
|
+
faraday.headers.update(@default_headers)
|
60
|
+
end
|
61
|
+
@connection.reconnect
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should pass a GET request through to Faraday preserving headers" do
|
65
|
+
stub_request(:get, "www.example.com/foo").
|
66
|
+
with(:headers => @default_headers).
|
67
|
+
to_return(body: "{result:true}")
|
68
|
+
|
69
|
+
result = @connection.get("/foo")
|
70
|
+
expect(result.body).to eq("{result:true}")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should pass a PUT request through to Faraday" do
|
74
|
+
stub_request(:put, "www.example.com/foo").
|
75
|
+
with(body: "body").
|
76
|
+
to_return(body: "{result:true}", :headers => @default_headers)
|
77
|
+
|
78
|
+
result = @connection.put("/foo", "body")
|
79
|
+
expect(result.body).to eq("{result:true}")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should pass a POST request through to Faraday" do
|
83
|
+
stub_request(:post, "www.example.com/foo").
|
84
|
+
with(body: "body", :headers => @default_headers).
|
85
|
+
to_return(body: "{result:true}")
|
86
|
+
|
87
|
+
result = @connection.post("/foo", "body")
|
88
|
+
expect(result.body).to eq("{result:true}")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should pass a DELETE request through to Faraday" do
|
92
|
+
stub_request(:delete, "www.example.com/foo").
|
93
|
+
with(:headers => @default_headers).
|
94
|
+
to_return(body: "{result:true}")
|
95
|
+
|
96
|
+
result = @connection.delete("/foo")
|
97
|
+
expect(result.body).to eq("{result:true}")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
48
101
|
it "should retry once in the event of a connection failed" do
|
49
102
|
stub_request(:get, "www.example.com/foo").to_raise(Faraday::ConnectionFailed.new("Foo"))
|
50
103
|
expect { @connection.get("/foo") }.to raise_error(ActiveRestClient::ConnectionFailedException)
|