active_rest_client 1.0.9 → 1.1.0

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.
@@ -69,6 +69,18 @@ describe ActiveRestClient::Configuration do
69
69
  ActiveRestClient::Base.username = nil
70
70
  end
71
71
 
72
+ it "should escape the username" do
73
+ ActiveRestClient::Base.username = "bill@example.com"
74
+ expect(ActiveRestClient::Base.username).to eq("bill%40example.com")
75
+ ActiveRestClient::Base.username = nil
76
+ end
77
+
78
+ it "should not doubly escape the username" do
79
+ ActiveRestClient::Base.username = "bill%40example.com"
80
+ expect(ActiveRestClient::Base.username).to_not eq("bill%2540example.com")
81
+ ActiveRestClient::Base.username = nil
82
+ end
83
+
72
84
  it "should remember the set password" do
73
85
  expect(ConfigurationExample.password).to eq("smith")
74
86
  end
@@ -79,6 +91,18 @@ describe ActiveRestClient::Configuration do
79
91
  ActiveRestClient::Base.password = nil
80
92
  end
81
93
 
94
+ it "should escape the password" do
95
+ ActiveRestClient::Base.password = "something@else"
96
+ expect(ActiveRestClient::Base.password).to eq("something%40else")
97
+ ActiveRestClient::Base.password = nil
98
+ end
99
+
100
+ it "should not doubly escape the password" do
101
+ ActiveRestClient::Base.password = "something%40else"
102
+ expect(ActiveRestClient::Base.password).to_not eq("something%2540else")
103
+ ActiveRestClient::Base.password = nil
104
+ end
105
+
82
106
  it "should default to a form_encoded request_body_type" do
83
107
  expect(ActiveRestClient::Base.request_body_type).to eq(:form_encoded)
84
108
  end
@@ -33,4 +33,11 @@ describe ActiveRestClient::ConnectionManager do
33
33
  found_connection = ActiveRestClient::ConnectionManager.find_connection_for_url("#{base_url}:8080/people/test")
34
34
  expect(found_connection).to eq(connection)
35
35
  end
36
+
37
+ it "should call 'in_parllel' for a session and yield procedure inside that block" do
38
+ ActiveRestClient::Base.adapter = :typhoeus
39
+ session = ActiveRestClient::ConnectionManager.get_connection("http://www.example.com").session
40
+ expect { |b| ActiveRestClient::ConnectionManager.in_parallel("http://www.example.com", &b)}.to yield_control
41
+ ActiveRestClient::Base._reset_configuration!
42
+ end
36
43
  end
@@ -28,7 +28,7 @@ describe ActiveRestClient::Instrumentation do
28
28
  expect_any_instance_of(ActiveRestClient::Connection).
29
29
  to receive(:get).
30
30
  with("/real", an_instance_of(Hash)).
31
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
31
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:200)))
32
32
  expect(ActiveRestClient::Logger).to receive(:debug).with(/ActiveRestClient.*ms\)/)
33
33
  expect(ActiveRestClient::Logger).to receive(:debug).at_least(:once).with(any_args)
34
34
  InstrumentationExampleClient.real
@@ -99,12 +99,12 @@ describe ActiveRestClient::Base do
99
99
  end
100
100
 
101
101
  it "has access to raw body content for requests" do
102
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/update", "MY-BODY-CONTENT", instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", status:200, headers:{}))
102
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/update", "MY-BODY-CONTENT", instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", status:200, response_headers:{})))
103
103
  ProxyClientExample.update(fname:"John", lname:"Smith")
104
104
  end
105
105
 
106
106
  it "handles DELETE requests" do
107
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:delete).with("/remove", instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", status:200, headers:{}))
107
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:delete).with("/remove", instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", status:200, response_headers:{})))
108
108
  ProxyClientExample.remove
109
109
  end
110
110
 
@@ -115,7 +115,7 @@ describe ActiveRestClient::Base do
115
115
  end
116
116
 
117
117
  it "can intercept the response and parse the response, alter it and pass it on during the request" do
118
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/change-format", instance_of(Hash)).and_return(OpenStruct.new(body:"{\"fname\":\"Billy\"}", status:200, headers:{}))
118
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/change-format", instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"fname\":\"Billy\"}", status:200, response_headers:{})))
119
119
  ret = ProxyClientExample.change_format
120
120
  expect(ret.first_name).to eq("Billy")
121
121
  end
@@ -128,7 +128,7 @@ describe ActiveRestClient::Base do
128
128
  end
129
129
 
130
130
  it "can continue with the request in the normal way, passing it on to the server" do
131
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/not_proxied?id=1", instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", status:200, headers:{}))
131
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/not_proxied?id=1", instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", status:200, response_headers:{})))
132
132
  ProxyClientExample.not_proxied(id:1)
133
133
  end
134
134
 
@@ -144,7 +144,7 @@ describe ActiveRestClient::Base do
144
144
  ProxyClientExample.perform_caching true
145
145
  allow(ProxyClientExample).to receive(:cache_store).and_return(cache_store)
146
146
  expiry = 10.minutes.from_now.rfc2822
147
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/update", "MY-BODY-CONTENT", instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", status:200, headers:{"Expires" => expiry, "ETag" => "123456"}))
147
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/update", "MY-BODY-CONTENT", instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", status:200, response_headers:{"Expires" => expiry, "ETag" => "123456"})))
148
148
  expect(ProxyClientExample.cache_store).to receive(:write) do |key, object, options|
149
149
  expect(key).to eq("ProxyClientExample:/update")
150
150
  expect(object).to be_an_instance_of(String)
@@ -162,8 +162,8 @@ describe ActiveRestClient::Base do
162
162
  end
163
163
 
164
164
  it "can force the URL from a filter without it being passed through URL replacement" do
165
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/hal_test/1", instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", status:200, headers:{}))
166
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/this/is/a/test", instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", status:200, headers:{}))
165
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/hal_test/1", instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", status:200, response_headers:{})))
166
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/this/is/a/test", instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", status:200, response_headers:{})))
167
167
  expect(ProxyClientExample.hal_test(id:1).test.result).to eq(true)
168
168
  end
169
169
 
@@ -74,24 +74,24 @@ describe ActiveRestClient::Request do
74
74
  it "should get an HTTP connection when called" do
75
75
  connection = double(ActiveRestClient::Connection).as_null_object
76
76
  expect(ActiveRestClient::ConnectionManager).to receive(:get_connection).with("http://www.example.com").and_return(connection)
77
- expect(connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
77
+ expect(connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
78
78
  ExampleClient.all
79
79
  end
80
80
 
81
81
  it "should get an HTTP connection with authentication when called" do
82
82
  connection = double(ActiveRestClient::Connection).as_null_object
83
83
  expect(ActiveRestClient::ConnectionManager).to receive(:get_connection).with("http://john:smith@www.example.com").and_return(connection)
84
- expect(connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
84
+ expect(connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
85
85
  AuthenticatedExampleClient.all
86
86
  end
87
87
 
88
88
  it "should get an HTTP connection when called and call get on it" do
89
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
89
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
90
90
  ExampleClient.all
91
91
  end
92
92
 
93
93
  it "should get an HTTP connection when called and call delete on it" do
94
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:delete).with("/remove/1", an_instance_of(Hash)).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
94
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:delete).with("/remove/1", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
95
95
  ExampleClient.remove(id:1)
96
96
  end
97
97
 
@@ -103,79 +103,79 @@ describe ActiveRestClient::Request do
103
103
  end
104
104
 
105
105
  it "should pass through get parameters" do
106
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/?debug=true", an_instance_of(Hash)).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
106
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/?debug=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
107
107
  ExampleClient.all debug:true
108
108
  end
109
109
 
110
110
  it "should pass through get parameters, using defaults specified" do
111
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/defaults?overwrite=yes&persist=yes", an_instance_of(Hash)).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
111
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/defaults?overwrite=yes&persist=yes", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
112
112
  ExampleClient.defaults overwrite:"yes"
113
113
  end
114
114
 
115
115
  it "should pass through url parameters" do
116
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/1234", an_instance_of(Hash)).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
116
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/1234", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
117
117
  ExampleClient.find id:1234
118
118
  end
119
119
 
120
120
  it "should accept an integer as the only parameter and use it as id" do
121
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/1234", an_instance_of(Hash)).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
121
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/1234", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
122
122
  ExampleClient.find(1234)
123
123
  end
124
124
 
125
125
  it "should accept a string as the only parameter and use it as id" do
126
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/1234", an_instance_of(Hash)).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
126
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/1234", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
127
127
  ExampleClient.find("1234")
128
128
  end
129
129
 
130
130
  it "should pass through url parameters and get parameters" do
131
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/1234?debug=true", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", headers:{}))
131
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/1234?debug=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
132
132
  ExampleClient.find id:1234, debug:true
133
133
  end
134
134
 
135
135
  it "should pass through url parameters and put parameters" do
136
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", "debug=true", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", headers:{}))
136
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", "debug=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
137
137
  ExampleClient.update id:1234, debug:true
138
138
  end
139
139
 
140
140
  it "should pass through 'array type' get parameters" do
141
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/?include%5B%5D=your&include%5B%5D=friends", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", headers:{}))
141
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/?include%5B%5D=your&include%5B%5D=friends", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
142
142
  ExampleClient.all :include => [:your,:friends]
143
143
  end
144
144
 
145
145
  it "should encode the body in a form-encoded format by default" do
146
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", "debug=true&test=foo", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", headers:{}))
146
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", "debug=true&test=foo", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
147
147
  ExampleClient.update id:1234, debug:true, test:'foo'
148
148
  end
149
149
 
150
150
  it "should encode the body in a JSON format if specified" do
151
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", %q({"debug":true,"test":"foo"}), an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", headers:{}))
151
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", %q({"debug":true,"test":"foo"}), an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
152
152
  ExampleClient.request_body_type :json
153
153
  ExampleClient.update id:1234, debug:true, test:'foo'
154
154
  end
155
155
 
156
156
  it "allows forcing a request_body_type per request" do
157
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:post).with("/encoding", %q({"id":1234,"test":"something"}), an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", headers:{}))
157
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:post).with("/encoding", %q({"id":1234,"test":"something"}), an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", response_headers:{})))
158
158
  ExampleClient.request_body_type :form_encoded # Should be ignored and the per_method :json used
159
159
  ExampleClient.test_encoding id:1234, test: "something"
160
160
  end
161
161
 
162
162
  it "should pass through custom headers" do
163
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/headers", hash_including("X-My-Header" => "myvalue")).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
163
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/headers", hash_including("X-My-Header" => "myvalue")).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
164
164
  ExampleClient.headers
165
165
  end
166
166
 
167
167
  it "should set request header with content-type for default" do
168
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/headers_default", "", hash_including("Content-Type" => "application/x-www-form-urlencoded")).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
168
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/headers_default", "", hash_including("Content-Type" => "application/x-www-form-urlencoded")).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
169
169
  ExampleClient.headers_default
170
170
  end
171
171
 
172
172
  it "should set request header with content-type for JSON" do
173
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/headers_json", "{}", hash_including("Content-Type" => "application/json; charset=utf-8")).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
173
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/headers_json", "{}", hash_including("Content-Type" => "application/json; charset=utf-8")).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
174
174
  ExampleClient.headers_json
175
175
  end
176
176
 
177
177
  it "should parse JSON to give a nice object" do
178
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", "debug=true", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true, \"list\":[1,2,3,{\"test\":true}], \"created_at\":\"2012-03-04T01:02:03Z\", \"child\":{\"grandchild\":{\"test\":true}}}", headers:{}))
178
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", "debug=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true, \"list\":[1,2,3,{\"test\":true}], \"created_at\":\"2012-03-04T01:02:03Z\", \"child\":{\"grandchild\":{\"test\":true}}}", response_headers:{})))
179
179
  object = ExampleClient.update id:1234, debug:true
180
180
  expect(object.result).to eq(true)
181
181
  expect(object.list.first).to eq(1)
@@ -223,7 +223,7 @@ describe ActiveRestClient::Request do
223
223
  end
224
224
 
225
225
  it "should parse an array within JSON to be a result iterator" do
226
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", "debug=true", an_instance_of(Hash)).and_return(OpenStruct.new(body:"[{\"first_name\":\"Johnny\"}, {\"first_name\":\"Billy\"}]", status:200, headers:{}))
226
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", "debug=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"[{\"first_name\":\"Johnny\"}, {\"first_name\":\"Billy\"}]", status:200, response_headers:{})))
227
227
  object = ExampleClient.update id:1234, debug:true
228
228
  expect(object).to be_instance_of(ActiveRestClient::ResultIterator)
229
229
  expect(object.first.first_name).to eq("Johnny")
@@ -232,25 +232,25 @@ describe ActiveRestClient::Request do
232
232
  end
233
233
 
234
234
  it "should instantiate other classes using has_many when required to do so" do
235
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, headers:{}))
235
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, response_headers:{})))
236
236
  object = ExampleClient.all
237
237
  expect(object.expenses.first).to be_instance_of(ExampleOtherClient)
238
238
  end
239
239
 
240
240
  it "should instantiate other classes using has_many even if nested off the root" do
241
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/babies", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"children\":{\"eldest\":[{\"name\":\"Billy\"}]}}", status:200, headers:{}))
241
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/babies", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"children\":{\"eldest\":[{\"name\":\"Billy\"}]}}", status:200, response_headers:{})))
242
242
  object = ExampleClient.babies
243
243
  expect(object.children.eldest.first).to be_instance_of(ExampleOtherClient)
244
244
  end
245
245
 
246
246
  it "should instantiate other classes using has_one when required to do so" do
247
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/single", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"single\":{\"name\":\"Billy\"}}", status:200, headers:{}))
247
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/single", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"single\":{\"name\":\"Billy\"}}", status:200, response_headers:{})))
248
248
  object = ExampleClient.single_association
249
249
  expect(object.single).to be_instance_of(ExampleSingleClient)
250
250
  end
251
251
 
252
252
  it "should instantiate other classes using has_one even if nested off the root" do
253
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/single", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"children\":[{\"single\":{\"name\":\"Billy\"}}, {\"single\":{\"name\":\"Sharon\"}}]}", status:200, headers:{}))
253
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/single", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"children\":[{\"single\":{\"name\":\"Billy\"}}, {\"single\":{\"name\":\"Sharon\"}}]}", status:200, response_headers:{})))
254
254
  object = ExampleClient.single_association
255
255
  expect(object.children.first.single).to be_instance_of(ExampleSingleClient)
256
256
  end
@@ -259,7 +259,7 @@ describe ActiveRestClient::Request do
259
259
  expect_any_instance_of(ActiveRestClient::Connection).
260
260
  to receive(:post).
261
261
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
262
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}))
262
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{})))
263
263
  object = ExampleClient.new(first_name:"John", should_disappear:true)
264
264
  object.create
265
265
  expect(object.first_name).to eq("John")
@@ -268,14 +268,21 @@ describe ActiveRestClient::Request do
268
268
  end
269
269
 
270
270
  it "should expose etag if available" do
271
- response = OpenStruct.new(body: "{}", headers: {"ETag" => "123456"}, status: 200)
271
+ response = ::FaradayResponseMock.new(OpenStruct.new(body: "{}", response_headers: {"ETag" => "123456"}, status: 200))
272
272
  expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/123", an_instance_of(Hash)).and_return(response)
273
273
  object = ExampleClient.find(123)
274
274
  expect(object._etag).to eq("123456")
275
275
  end
276
276
 
277
277
  it "should expose all headers" do
278
- response = OpenStruct.new(body: "{}", headers: {"X-Test-Header" => "true"}, status: 200)
278
+ response = ::FaradayResponseMock.new(OpenStruct.new(body: "{}", response_headers: {"X-Test-Header" => "true"}, status: 200))
279
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/123", an_instance_of(Hash)).and_return(response)
280
+ object = ExampleClient.find(123)
281
+ expect(object._headers["X-Test-Header"]).to eq("true")
282
+ end
283
+
284
+ it "should expose all headers on collection" do
285
+ response = ::FaradayResponseMock.new(OpenStruct.new(body: "[{}]", response_headers: {"X-Test-Header" => "true"}, status: 200))
279
286
  expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/123", an_instance_of(Hash)).and_return(response)
280
287
  object = ExampleClient.find(123)
281
288
  expect(object._headers["X-Test-Header"]).to eq("true")
@@ -285,7 +292,7 @@ describe ActiveRestClient::Request do
285
292
  expect_any_instance_of(ActiveRestClient::Connection).
286
293
  to receive(:post).
287
294
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
288
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
295
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:200)))
289
296
  expect(ActiveRestClient::Logger).to receive(:info).with(%r'Requesting http://www.example.com/create')
290
297
  expect(ActiveRestClient::Logger).to receive(:debug).at_least(1).times.with(%r'(Response received \d+ bytes|Trying to read from cache)')
291
298
 
@@ -298,7 +305,7 @@ describe ActiveRestClient::Request do
298
305
  expect_any_instance_of(ActiveRestClient::Connection).
299
306
  to receive(:post).
300
307
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
301
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
308
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:200)))
302
309
  expect(ActiveRestClient::Logger).to receive(:info).with(%r'Requesting http://www.example.com/create')
303
310
  expect(ActiveRestClient::Logger).to receive(:debug).at_least(1).times.with(%r'(Response received \d+ bytes|Trying to read from cache)')
304
311
 
@@ -310,7 +317,7 @@ describe ActiveRestClient::Request do
310
317
  expect_any_instance_of(ActiveRestClient::Connection).
311
318
  to receive(:post).
312
319
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
313
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
320
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:200)))
314
321
  expect(ActiveRestClient::Logger).to receive(:debug).with(/ POST /)
315
322
  allow(ActiveRestClient::Logger).to receive(:debug).with(any_args)
316
323
 
@@ -321,7 +328,7 @@ describe ActiveRestClient::Request do
321
328
  it "should verbose log if enabled" do
322
329
  connection = double(ActiveRestClient::Connection).as_null_object
323
330
  expect(ActiveRestClient::ConnectionManager).to receive(:get_connection).and_return(connection)
324
- expect(connection).to receive(:get).with("/all", an_instance_of(Hash)).and_return(OpenStruct.new(body:'{"result":true}', headers:{"Content-Type" => "application/json", "Connection" => "close"}))
331
+ expect(connection).to receive(:get).with("/all", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{"Content-Type" => "application/json", "Connection" => "close"})))
325
332
  expect(ActiveRestClient::Logger).to receive(:debug).with("ActiveRestClient Verbose Log:")
326
333
  expect(ActiveRestClient::Logger).to receive(:debug).with(/ >> /).at_least(:twice)
327
334
  expect(ActiveRestClient::Logger).to receive(:debug).with(/ << /).at_least(:twice)
@@ -333,7 +340,7 @@ describe ActiveRestClient::Request do
333
340
  expect_any_instance_of(ActiveRestClient::Connection).
334
341
  to receive(:post).
335
342
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
336
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:401))
343
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:401)))
337
344
  object = ExampleClient.new(first_name:"John", should_disappear:true)
338
345
  begin
339
346
  object.create
@@ -349,7 +356,7 @@ describe ActiveRestClient::Request do
349
356
  expect_any_instance_of(ActiveRestClient::Connection).
350
357
  to receive(:post).
351
358
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
352
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:403))
359
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:403)))
353
360
  object = ExampleClient.new(first_name:"John", should_disappear:true)
354
361
  begin
355
362
  object.create
@@ -365,7 +372,7 @@ describe ActiveRestClient::Request do
365
372
  expect_any_instance_of(ActiveRestClient::Connection).
366
373
  to receive(:post).
367
374
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
368
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:404))
375
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:404)))
369
376
  object = ExampleClient.new(first_name:"John", should_disappear:true)
370
377
  begin
371
378
  object.create
@@ -381,7 +388,7 @@ describe ActiveRestClient::Request do
381
388
  expect_any_instance_of(ActiveRestClient::Connection).
382
389
  to receive(:post).
383
390
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
384
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:409))
391
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:409)))
385
392
  object = ExampleClient.new(first_name:"John", should_disappear:true)
386
393
  begin
387
394
  object.create
@@ -397,7 +404,7 @@ describe ActiveRestClient::Request do
397
404
  expect_any_instance_of(ActiveRestClient::Connection).
398
405
  to receive(:post).
399
406
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
400
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:500))
407
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:500)))
401
408
  object = ExampleClient.new(first_name:"John", should_disappear:true)
402
409
  begin
403
410
  object.create
@@ -414,7 +421,7 @@ describe ActiveRestClient::Request do
414
421
  expect_any_instance_of(ActiveRestClient::Connection).
415
422
  to receive(:post).
416
423
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
417
- and_return(OpenStruct.new(body:error_content, headers:{'Content-Type' => 'text/html'}, status:500))
424
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:error_content, response_headers:{'Content-Type' => 'text/html'}, status:500)))
418
425
  object = ExampleClient.new(first_name:"John", should_disappear:true)
419
426
  begin
420
427
  object.create
@@ -431,7 +438,7 @@ describe ActiveRestClient::Request do
431
438
  expect_any_instance_of(ActiveRestClient::Connection).
432
439
  to receive(:post).
433
440
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
434
- and_return(OpenStruct.new(body:error_content, headers:{'Content-Type' => 'text/html'}, status:400))
441
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:error_content, response_headers:{'Content-Type' => 'text/html'}, status:400)))
435
442
  object = ExampleClient.new(first_name:"John", should_disappear:true)
436
443
  begin
437
444
  object.create
@@ -448,7 +455,7 @@ describe ActiveRestClient::Request do
448
455
  expect_any_instance_of(ActiveRestClient::Connection).
449
456
  to receive(:post).
450
457
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
451
- and_return(OpenStruct.new(body:error_content, headers:{'Content-Type' => 'text/html'}, status:200))
458
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:error_content, response_headers:{'Content-Type' => 'text/html'}, status:200)))
452
459
  object = ExampleClient.new(first_name:"John", should_disappear:true)
453
460
  begin
454
461
  object.create
@@ -464,7 +471,7 @@ describe ActiveRestClient::Request do
464
471
  expect_any_instance_of(ActiveRestClient::Connection).
465
472
  to receive(:post).
466
473
  with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
467
- and_return(OpenStruct.new(body:'{"errors": ["validation": "error in validation"]}', headers:{'Content-Type' => 'text/html'}, status:400))
474
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"errors": ["validation": "error in validation"]}', response_headers:{'Content-Type' => 'text/html'}, status:400)))
468
475
  object = ExampleClient.new(first_name:"John", should_disappear:true)
469
476
  begin
470
477
  object.create
@@ -474,20 +481,18 @@ describe ActiveRestClient::Request do
474
481
  expect(e).to be_instance_of(ActiveRestClient::HTTPBadRequestClientException)
475
482
  expect(e.status).to eq(400)
476
483
  expect(object.first_name).to eq 'John'
477
- expect(object.errors).to be_nil
484
+ expect(object.errors).to eq(nil)
478
485
  end
479
486
 
480
487
  it "should raise an exception if you try to pass in an unsupport method" do
481
488
  method = {:method => :wiggle, url:"/"}
482
- class RequestFakeObject
489
+ class RequestFakeObject < ActiveRestClient::Base
490
+ base_url "http://www.example.com/"
491
+
483
492
  def request_body_type
484
493
  :form_encoded
485
494
  end
486
495
 
487
- def base_url
488
- "http://www.example.com/"
489
- end
490
-
491
496
  def username ; end
492
497
  def password ; end
493
498
  def name ; end
@@ -501,20 +506,20 @@ describe ActiveRestClient::Request do
501
506
  end
502
507
 
503
508
  it "should send all class mapped methods through _filter_request" do
504
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, headers:{}))
509
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, response_headers:{})))
505
510
  expect(ExampleClient).to receive(:_filter_request).with(any_args).exactly(2).times
506
511
  ExampleClient.all
507
512
  end
508
513
 
509
514
  it "should send all instance mapped methods through _filter_request" do
510
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, headers:{}))
515
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, response_headers:{})))
511
516
  expect(ExampleClient).to receive(:_filter_request).with(any_args).exactly(2).times
512
517
  e = ExampleClient.new
513
518
  e.all
514
519
  end
515
520
 
516
521
  it "should change the generated object if an after_filter changes it" do
517
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/change", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, headers:{}))
522
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/change", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, response_headers:{})))
518
523
  obj = ExampleClient.change
519
524
  expect(obj.test).to eq(1)
520
525
  end
@@ -537,7 +542,7 @@ describe ActiveRestClient::Request do
537
542
  expect_any_instance_of(ActiveRestClient::Connection).
538
543
  to receive(:get).
539
544
  with("/some/url", an_instance_of(Hash)).
540
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
545
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:200)))
541
546
  SameServerExampleClient.same_server
542
547
  end
543
548
 
@@ -547,7 +552,7 @@ describe ActiveRestClient::Request do
547
552
  expect(connection).
548
553
  to receive(:get).
549
554
  with("/some/url", an_instance_of(Hash)).
550
- and_return(OpenStruct.new(body:"{}", headers:{}, status:304))
555
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{}", response_headers:{}, status:304)))
551
556
  allow(connection).
552
557
  to receive(:base_url).
553
558
  and_return("http://other.example.com")
@@ -563,7 +568,7 @@ describe ActiveRestClient::Request do
563
568
  expect(connection).
564
569
  to receive(:get).
565
570
  with("/v1/people", an_instance_of(Hash)).
566
- and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
571
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:200)))
567
572
  @obj = SameServerExampleClient._request('/people')
568
573
  end
569
574
  end
@@ -573,7 +578,7 @@ describe ActiveRestClient::Request do
573
578
  let(:hal) { ExampleClient.hal }
574
579
 
575
580
  it "should request a HAL response or plain JSON" do
576
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/headers", hash_including("Accept" => "application/hal+json, application/json;q=0.5")).and_return(OpenStruct.new(body:'{"result":true}', headers:{}))
581
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/headers", hash_including("Accept" => "application/hal+json, application/json;q=0.5")).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
577
582
  ExampleClient.headers
578
583
  end
579
584
 
@@ -589,17 +594,17 @@ describe ActiveRestClient::Request do
589
594
  end
590
595
  fake_object = RequestFakeObject.new
591
596
  request = ActiveRestClient::Request.new(method, fake_object, {})
592
- request.instance_variable_set(:@response, OpenStruct.new(headers:{"Content-Type" => "application/hal+json"}))
597
+ request.instance_variable_set(:@response, OpenStruct.new(response_headers:{"Content-Type" => "application/hal+json"}))
593
598
  expect(request.hal_response?).to be_truthy
594
- request.instance_variable_set(:@response, OpenStruct.new(headers:{"Content-Type" => "application/json"}))
599
+ request.instance_variable_set(:@response, OpenStruct.new(response_headers:{"Content-Type" => "application/json"}))
595
600
  expect(request.hal_response?).to be_truthy
596
- request.instance_variable_set(:@response, OpenStruct.new(headers:{"Content-Type" => "text/plain"}))
601
+ request.instance_variable_set(:@response, OpenStruct.new(response_headers:{"Content-Type" => "text/plain"}))
597
602
  expect(request.hal_response?).to be_falsey
598
- request.instance_variable_set(:@response, OpenStruct.new(headers:{"Content-Type" => ["text/plain", "application/hal+json"]}))
603
+ request.instance_variable_set(:@response, OpenStruct.new(response_headers:{"Content-Type" => ["text/plain", "application/hal+json"]}))
599
604
  expect(request.hal_response?).to be_truthy
600
- request.instance_variable_set(:@response, OpenStruct.new(headers:{"Content-Type" => ["text/plain", "application/json"]}))
605
+ request.instance_variable_set(:@response, OpenStruct.new(response_headers:{"Content-Type" => ["text/plain", "application/json"]}))
601
606
  expect(request.hal_response?).to be_truthy
602
- request.instance_variable_set(:@response, OpenStruct.new(headers:{"Content-Type" => ["text/plain"]}))
607
+ request.instance_variable_set(:@response, OpenStruct.new(response_headers:{"Content-Type" => ["text/plain"]}))
603
608
  expect(request.hal_response?).to be_falsey
604
609
  end
605
610
 
@@ -633,7 +638,59 @@ describe ActiveRestClient::Request do
633
638
  end
634
639
 
635
640
  it "replaces the body completely in a filter" do
636
- expect_any_instance_of(ActiveRestClient::Connection).to receive(:post).with("/save", "{\"id\":1234,\"name\":\"john\"}", an_instance_of(Hash)).and_return(OpenStruct.new(body:"{}", headers:{}))
641
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:post).with("/save", "{\"id\":1234,\"name\":\"john\"}", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{}", response_headers:{})))
637
642
  FilteredBodyExampleClient.save id:1234, name:'john'
638
643
  end
644
+
645
+ context 'Simulating Faraday connection in_parallel' do
646
+ it 'should parse JSON and return a single object' do
647
+ response = ::FaradayResponseMock.new(
648
+ OpenStruct.new(body:"{\"result\":true, \"list\":[1,2,3,{\"test\":true}], \"created_at\":\"2012-03-04T01:02:03Z\", \"child\":{\"grandchild\":{\"test\":true}}}", response_headers:{}),
649
+ false)
650
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", "debug=true", an_instance_of(Hash)).and_return(response)
651
+ object = ExampleClient.update id:1234, debug:true
652
+
653
+ expect(object).to eq(nil)
654
+
655
+ response.finish
656
+ expect(object.result).to eq(true)
657
+ expect(object.list.first).to eq(1)
658
+ expect(object.list.last.test).to eq(true)
659
+ expect(object.created_at).to be_an_instance_of(DateTime)
660
+ expect(object.child.grandchild.test).to eq(true)
661
+ end
662
+
663
+ it 'should parse an array within JSON and return a result iterator' do
664
+ response = ::FaradayResponseMock.new(
665
+ OpenStruct.new(body:"[{\"first_name\":\"Johnny\"}, {\"first_name\":\"Billy\"}]", status:200, response_headers:{}),
666
+ false)
667
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(response)
668
+ object = ExampleClient.all
669
+
670
+ expect(object).to eq(nil)
671
+
672
+ response.finish
673
+ expect(object).to be_instance_of(ActiveRestClient::ResultIterator)
674
+ expect(object.first.first_name).to eq("Johnny")
675
+ expect(object[1].first_name).to eq("Billy")
676
+ expect(object._status).to eq(200)
677
+ object.each do |item|
678
+ expect(item).to_not be_nil
679
+ end
680
+ end
681
+
682
+ it 'should return a RequestDelegator object to wrap the result' do
683
+ response = ::FaradayResponseMock.new(
684
+ OpenStruct.new(body:"{\"result\":true, \"list\":[1,2,3,{\"test\":true}], \"created_at\":\"2012-03-04T01:02:03Z\", \"child\":{\"grandchild\":{\"test\":true}}}", response_headers:{}),
685
+ false)
686
+ expect_any_instance_of(ActiveRestClient::Connection).to receive(:put).with("/put/1234", "debug=true", an_instance_of(Hash)).and_return(response)
687
+ object = ExampleClient.update id:1234, debug:true
688
+ response.finish
689
+
690
+ expect(object.class).to eq(ExampleClient)
691
+ expect(object.kind_of?(ExampleClient)).to be_truthy
692
+ expect(object.is_a?(ExampleClient)).to be_truthy
693
+ expect(object._delegate?).to be_truthy
694
+ end
695
+ end
639
696
  end
@@ -1,11 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveRestClient::ResultIterator do
4
+ let(:response) { double(status: 200, response_headers: { some: 'header'}) }
5
+
4
6
  it "should be able to have a status set during creation" do
5
- result = ActiveRestClient::ResultIterator.new(200)
7
+ result = ActiveRestClient::ResultIterator.new(response)
6
8
  expect(result._status).to eq(200)
7
9
  end
8
10
 
11
+ it "should be able to have headers set during creation" do
12
+ result = ActiveRestClient::ResultIterator.new(response)
13
+ expect(result._headers).to eq({ some: 'header'})
14
+ end
15
+
9
16
  it "should be able to have a status set after creation" do
10
17
  result = ActiveRestClient::ResultIterator.new
11
18
  result._status = 200