active_rest_client 0.9.60 → 0.9.65
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -1
- data/Rakefile +8 -0
- data/lib/active_rest_client.rb +1 -1
- data/lib/active_rest_client/base.rb +8 -2
- data/lib/active_rest_client/caching.rb +10 -3
- data/lib/active_rest_client/connection_manager.rb +7 -7
- data/lib/active_rest_client/lazy_association_loader.rb +5 -4
- data/lib/active_rest_client/proxy_base.rb +2 -0
- data/lib/active_rest_client/request.rb +16 -3
- data/lib/active_rest_client/version.rb +1 -1
- data/spec/lib/base_spec.rb +29 -0
- data/spec/lib/caching_spec.rb +12 -6
- data/spec/lib/connection_manager_spec.rb +1 -1
- data/spec/lib/connection_spec.rb +2 -2
- data/spec/lib/proxy_spec.rb +13 -4
- data/spec/lib/request_spec.rb +3 -2
- data/spec/spec_helper.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25402e9d8bfc6b6a100bc3879d52ab05bf6b405d
|
4
|
+
data.tar.gz: 1008478bfd788080beace5892d18ebfce789e0f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89b51eef05da436ab06c8e7f26b710ec3ef23f7c98877338b67a91832d73bde76d9b35a1385900155b61c063c5b27166c726b2515f6c66c010e1e0193b18cf3
|
7
|
+
data.tar.gz: bfd28ddd34cd232649ec40cb7924e72ef30b6981076aed71f1df88d7c1a416fa611147a4a068244b6e31db504917a41821ae1cb7c71b17e7c3c88f127cf18ba0
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ class Person < ActiveRestClient::Base
|
|
40
40
|
end
|
41
41
|
```
|
42
42
|
|
43
|
-
Note I've specified the base_url in the class above. This is
|
43
|
+
Note I've specified the base_url in the class above. This is useful where you want to be explicit or use different APIs for some classes and be explicit. If you have one server that's generally used, you can set it once with a simple line in the application.rb/production.rb:
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
ActiveRestClient::Base.base_url = "https://www.example.com/api/v1"
|
@@ -394,6 +394,22 @@ This initially creates an ActiveRestClient::Request object as if you'd called `P
|
|
394
394
|
|
395
395
|
Doing this will try to find a literally mapped method called "lazy_find" and if it fails, it will try to use "find" but instantiate the object lazily.
|
396
396
|
|
397
|
+
### Plain Requests
|
398
|
+
|
399
|
+
If you are already using ActiveRestClient but then want to simply call a normal URL and receive the resulting content as a string (i.e. not going through JSON parsing or instantiating in to an ActiveRestClient::Base descendent) you can use code like this:
|
400
|
+
|
401
|
+
```ruby
|
402
|
+
class Person < ActiveRestClient::Base
|
403
|
+
end
|
404
|
+
|
405
|
+
people = Person._plain_request('http://api.example.com/v1/people') # Defaults to get with no parameters
|
406
|
+
# people is a normal ActiveRestClient object, implementing iteration, HAL loading, etc.
|
407
|
+
|
408
|
+
Person._plain_request('http://api.example.com/v1/people', :post, {id:1234,name:"John"}) # Post with parameters
|
409
|
+
```
|
410
|
+
|
411
|
+
The parameters are the same as for _request, but it does no parsing on the response
|
412
|
+
|
397
413
|
### Proxying APIs
|
398
414
|
|
399
415
|
Sometimes you may be working with an old API that returns JSON in a less than ideal format or the URL or parameters required have changed. In this case you can define a descendent of `ActiveRestClient::ProxyBase`, pass it to your model as the proxy and have it rework URLs/parameters on the way out and the response on the way back in (already converted to a Ruby hash/array). By default any non-proxied URLs are just passed through to the underlying connection layer. For example:
|
data/Rakefile
CHANGED
data/lib/active_rest_client.rb
CHANGED
@@ -52,13 +52,19 @@ module ActiveRestClient
|
|
52
52
|
prepare_direct_request(request, method).call(params)
|
53
53
|
end
|
54
54
|
|
55
|
+
def self._plain_request(request, method = :get, params = nil)
|
56
|
+
prepare_direct_request(request, method, plain:true).call(params)
|
57
|
+
end
|
58
|
+
|
55
59
|
def self._lazy_request(request, method = :get, params = nil)
|
56
60
|
ActiveRestClient::LazyLoader.new(prepare_direct_request(request, method), params)
|
57
61
|
end
|
58
62
|
|
59
|
-
def self.prepare_direct_request(request, method)
|
63
|
+
def self.prepare_direct_request(request, method, options={})
|
60
64
|
unless request.is_a? ActiveRestClient::Request
|
61
|
-
|
65
|
+
options[:plain] ||= false
|
66
|
+
mapped = {url:"DIRECT-CALLED-#{request}", method:method, options:{url:request, plain:options[:plain]}}
|
67
|
+
|
62
68
|
request = Request.new(mapped, self)
|
63
69
|
end
|
64
70
|
request
|
@@ -21,6 +21,7 @@ module ActiveRestClient
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def cache_store=(value)
|
24
|
+
@@cache_store = nil if value.nil? and return
|
24
25
|
raise InvalidCacheStoreException.new("Cache store does not implement #read") unless value.respond_to?(:read)
|
25
26
|
raise InvalidCacheStoreException.new("Cache store does not implement #write") unless value.respond_to?(:write)
|
26
27
|
raise InvalidCacheStoreException.new("Cache store does not implement #fetch") unless value.respond_to?(:fetch)
|
@@ -43,13 +44,19 @@ module ActiveRestClient
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def read_cached_response(request)
|
46
|
-
if cache_store
|
47
|
+
if cache_store && perform_caching
|
47
48
|
key = "#{request.class_name}:#{request.original_url}"
|
48
|
-
|
49
|
+
ActiveRestClient::Logger.debug " \033[1;4;32m#{ActiveRestClient::NAME}\033[0m #{key} - Reading from cache"
|
50
|
+
value = cache_store.read(key)
|
51
|
+
value = Marshal.load(value) rescue value
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
52
55
|
def write_cached_response(request, response, result)
|
56
|
+
return if result.is_a? Symbol
|
57
|
+
return unless perform_caching
|
58
|
+
return unless !result.respond_to?(:_status) || [200, 304].include?(result._status)
|
59
|
+
|
53
60
|
response.headers.keys.select{|h| h.is_a? String}.each do |key|
|
54
61
|
response.headers[key.downcase.to_sym] = response.headers[key]
|
55
62
|
end
|
@@ -60,7 +67,7 @@ module ActiveRestClient
|
|
60
67
|
cached_response = CachedResponse.new(status:response.status, result:result)
|
61
68
|
cached_response.etag = response.headers[:etag] if response.headers[:etag]
|
62
69
|
cached_response.expires = Time.parse(response.headers[:expires]) if response.headers[:expires]
|
63
|
-
cache_store.write(key, cached_response, {})
|
70
|
+
cache_store.write(key, Marshal.dump(cached_response), {})
|
64
71
|
end
|
65
72
|
end
|
66
73
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module ActiveRestClient
|
2
2
|
class ConnectionManager
|
3
3
|
def self.reset!
|
4
|
-
|
4
|
+
Thread.current[:_connections]={}
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.get_connection(base_url)
|
8
8
|
raise Exception.new("Nil base URL passed to ConnectionManager.get_connection") if base_url.nil?
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Thread.current[:_connections] ||= {}
|
10
|
+
Thread.current[:_connections][base_url] ||= Connection.new(base_url)
|
11
|
+
Thread.current[:_connections][base_url]
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.find_connection_for_url(url)
|
15
|
-
|
16
|
-
found =
|
17
|
-
|
15
|
+
Thread.current[:_connections] ||= {}
|
16
|
+
found = Thread.current[:_connections].keys.detect {|key| url[0,key.length] == key}
|
17
|
+
Thread.current[:_connections][found] if found
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
@@ -80,10 +80,11 @@ module ActiveRestClient
|
|
80
80
|
|
81
81
|
def ensure_lazy_loaded
|
82
82
|
if @object.nil?
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
method=@request.method.dup
|
84
|
+
method[:method] = :get
|
85
|
+
method[:options][:url] = @url
|
86
|
+
method[:options][:overriden_name] = @options[:overriden_name]
|
87
|
+
request = ActiveRestClient::Request.new(method, @request.object)
|
87
88
|
request.url = request.forced_url = @url
|
88
89
|
@object = request.call
|
89
90
|
end
|
@@ -28,6 +28,14 @@ module ActiveRestClient
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
def original_object_class
|
32
|
+
if object_is_class?
|
33
|
+
@object
|
34
|
+
else
|
35
|
+
@object.class
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
31
39
|
def base_url
|
32
40
|
if object_is_class?
|
33
41
|
@object.base_url
|
@@ -87,12 +95,12 @@ module ActiveRestClient
|
|
87
95
|
append_get_parameters
|
88
96
|
prepare_request_body
|
89
97
|
self.original_url = self.url
|
90
|
-
cached =
|
98
|
+
cached = original_object_class.read_cached_response(self)
|
91
99
|
if cached
|
92
100
|
if cached.expires && cached.expires > Time.now
|
93
101
|
ActiveRestClient::Logger.debug " \033[1;4;32m#{ActiveRestClient::NAME}\033[0m #{@instrumentation_name} - Absolutely cached copy found"
|
94
102
|
return handle_cached_response(cached)
|
95
|
-
elsif cached.etag.present?
|
103
|
+
elsif cached.etag.to_s != "" #present? isn't working for some reason
|
96
104
|
ActiveRestClient::Logger.debug " \033[1;4;32m#{ActiveRestClient::NAME}\033[0m #{@instrumentation_name} - Etag cached copy found with etag #{cached.etag}"
|
97
105
|
etag = cached.etag
|
98
106
|
end
|
@@ -111,7 +119,7 @@ module ActiveRestClient
|
|
111
119
|
if result == :not_modified && cached
|
112
120
|
result = cached.result
|
113
121
|
end
|
114
|
-
|
122
|
+
original_object_class.write_cached_response(self, response, result)
|
115
123
|
result
|
116
124
|
end
|
117
125
|
end
|
@@ -246,6 +254,11 @@ module ActiveRestClient
|
|
246
254
|
else
|
247
255
|
ActiveRestClient::Logger.debug " \033[1;4;32m#{ActiveRestClient::NAME}\033[0m #{@instrumentation_name} - Response received #{response.body.size} bytes"
|
248
256
|
end
|
257
|
+
|
258
|
+
if @method[:options][:plain]
|
259
|
+
return @response = response.body
|
260
|
+
end
|
261
|
+
|
249
262
|
@response = response
|
250
263
|
|
251
264
|
if response.body.is_a?(Array) || response.body.is_a?(Hash)
|
data/spec/lib/base_spec.rb
CHANGED
@@ -214,6 +214,35 @@ describe ActiveRestClient::Base do
|
|
214
214
|
expect(example.first_name).to eq("Billy")
|
215
215
|
end
|
216
216
|
|
217
|
+
it "should be able to pass the plain response from the directly called URL bypassing JSON loading" do
|
218
|
+
response = OpenStruct.new(_status:200, body:"This is another non-JSON string")
|
219
|
+
ActiveRestClient::Connection.any_instance.should_receive(:post).with(any_args).and_return(OpenStruct.new(status:200, headers:{}, body:response))
|
220
|
+
expect(EmptyExample._plain_request("http://api.example.com/", :post, {id:1234})).to eq(response)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should cache plain requests separately" do
|
224
|
+
perform_caching = EmptyExample.perform_caching
|
225
|
+
cache_store = EmptyExample.cache_store
|
226
|
+
begin
|
227
|
+
response = OpenStruct.new(_status:200, body:"This is a non-JSON string")
|
228
|
+
other_response = OpenStruct.new(_status:200, body:"This is another non-JSON string")
|
229
|
+
allow_any_instance_of(ActiveRestClient::Connection).to receive(:get) do |url, others|
|
230
|
+
if url == "/?test=1"
|
231
|
+
OpenStruct.new(status:200, headers:{}, body:response)
|
232
|
+
else
|
233
|
+
OpenStruct.new(status:200, headers:{}, body:other_response)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
EmptyExample.perform_caching = true
|
237
|
+
EmptyExample.cache_store = TestCacheStore.new
|
238
|
+
expect(EmptyExample._plain_request("http://api.example.com/?test=1")).to eq(response)
|
239
|
+
expect(EmptyExample._plain_request("http://api.example.com/?test=2")).to eq(other_response)
|
240
|
+
ensure
|
241
|
+
EmptyExample.perform_caching = perform_caching
|
242
|
+
EmptyExample.cache_store = cache_store
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
217
246
|
it "should be able to lazy load a direct URL request" do
|
218
247
|
ActiveRestClient::Request.any_instance.should_receive(:do_request).with(any_args).and_return(OpenStruct.new(status:200, headers:{}, body:"{\"first_name\":\"Billy\"}"))
|
219
248
|
example = EmptyExample._lazy_request("http://api.example.com/")
|
data/spec/lib/caching_spec.rb
CHANGED
@@ -78,6 +78,10 @@ describe ActiveRestClient::Caching do
|
|
78
78
|
expect{ ActiveRestClient::Base.cache_store = CachingExampleCacheStore3.new }.to raise_error
|
79
79
|
expect{ ActiveRestClient::Base.cache_store = CachingExampleCacheStore4.new }.to raise_error
|
80
80
|
end
|
81
|
+
|
82
|
+
it "should allow you to remove the custom cache store" do
|
83
|
+
expect{ ActiveRestClient::Base.cache_store = nil }.to_not raise_error
|
84
|
+
end
|
81
85
|
end
|
82
86
|
|
83
87
|
context "Reading/writing to the cache" do
|
@@ -106,7 +110,7 @@ describe ActiveRestClient::Caching do
|
|
106
110
|
status:200,
|
107
111
|
result:@cached_object,
|
108
112
|
etag:@etag)
|
109
|
-
CachingExampleCacheStore5.any_instance.should_receive(:read).once.with("Person:/").and_return(cached_response)
|
113
|
+
CachingExampleCacheStore5.any_instance.should_receive(:read).once.with("Person:/").and_return(Marshal.dump(cached_response))
|
110
114
|
ActiveRestClient::Connection.any_instance.should_receive(:get).with("/", hash_including("If-None-Match" => @etag)).and_return(OpenStruct.new(status:304, headers:{}))
|
111
115
|
ret = Person.all
|
112
116
|
expect(ret.first_name).to eq("Johnny")
|
@@ -117,7 +121,7 @@ describe ActiveRestClient::Caching do
|
|
117
121
|
status:200,
|
118
122
|
result:@cached_object,
|
119
123
|
expires:Time.now + 30)
|
120
|
-
CachingExampleCacheStore5.any_instance.should_receive(:read).once.with("Person:/").and_return(cached_response)
|
124
|
+
CachingExampleCacheStore5.any_instance.should_receive(:read).once.with("Person:/").and_return(Marshal.dump(cached_response))
|
121
125
|
ActiveRestClient::Connection.any_instance.should_not_receive(:get)
|
122
126
|
ret = Person.all
|
123
127
|
expect(ret.first_name).to eq("Johnny")
|
@@ -128,7 +132,7 @@ describe ActiveRestClient::Caching do
|
|
128
132
|
status:200,
|
129
133
|
result:@cached_object,
|
130
134
|
expires:Time.now + 30)
|
131
|
-
CachingExampleCacheStore5.any_instance.should_receive(:read).once.with("Person:/").and_return(cached_response)
|
135
|
+
CachingExampleCacheStore5.any_instance.should_receive(:read).once.with("Person:/").and_return(Marshal.dump(cached_response))
|
132
136
|
ActiveRestClient::Connection.any_instance.should_not_receive(:get)
|
133
137
|
p = Person.new(first_name:"Billy")
|
134
138
|
ret = p.all({})
|
@@ -146,7 +150,7 @@ describe ActiveRestClient::Caching do
|
|
146
150
|
result:object,
|
147
151
|
etag:@etag,
|
148
152
|
expires:Time.now + 30)
|
149
|
-
CachingExampleCacheStore5.any_instance.should_receive(:read).once.with("Person:/").and_return(cached_response)
|
153
|
+
CachingExampleCacheStore5.any_instance.should_receive(:read).once.with("Person:/").and_return(Marshal.dump(cached_response))
|
150
154
|
ActiveRestClient::Connection.any_instance.should_not_receive(:get)
|
151
155
|
ret = Person.all
|
152
156
|
expect(ret.first.first_name).to eq("Johnny")
|
@@ -162,15 +166,17 @@ describe ActiveRestClient::Caching do
|
|
162
166
|
|
163
167
|
it "should write the response to the cache if there's an etag" do
|
164
168
|
CachingExampleCacheStore5.any_instance.should_receive(:read).once.with("Person:/").and_return(nil)
|
165
|
-
CachingExampleCacheStore5.any_instance.should_receive(:write).once.with("Person:/", an_instance_of(
|
169
|
+
CachingExampleCacheStore5.any_instance.should_receive(:write).once.with("Person:/", an_instance_of(String), {})
|
166
170
|
ActiveRestClient::Connection.any_instance.should_receive(:get).with("/", an_instance_of(Hash)).and_return(OpenStruct.new(status:200, body:"{\"result\":true}", headers:{etag:"1234567890"}))
|
171
|
+
Person.perform_caching true
|
167
172
|
ret = Person.all
|
168
173
|
end
|
169
174
|
|
170
175
|
it "should write the response to the cache if there's a hard expiry" do
|
171
176
|
CachingExampleCacheStore5.any_instance.should_receive(:read).once.with("Person:/").and_return(nil)
|
172
|
-
CachingExampleCacheStore5.any_instance.should_receive(:write).once.with("Person:/", an_instance_of(
|
177
|
+
CachingExampleCacheStore5.any_instance.should_receive(:write).once.with("Person:/", an_instance_of(String), an_instance_of(Hash))
|
173
178
|
ActiveRestClient::Connection.any_instance.should_receive(:get).with("/", an_instance_of(Hash)).and_return(OpenStruct.new(status:200, body:"{\"result\":true}", headers:{expires:(Time.now + 30).rfc822}))
|
179
|
+
Person.perform_caching = true
|
174
180
|
ret = Person.all
|
175
181
|
end
|
176
182
|
|
@@ -24,7 +24,7 @@ describe ActiveRestClient::ConnectionManager do
|
|
24
24
|
other_base_url = "http://other.example.com"
|
25
25
|
expect(ActiveRestClient::ConnectionManager.get_connection(base_url).base_url).to eq(base_url)
|
26
26
|
expect(ActiveRestClient::ConnectionManager.get_connection(other_base_url).base_url).to eq(other_base_url)
|
27
|
-
expect(
|
27
|
+
expect(Thread.current[:_connections].size).to eq(2)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should find a connection if you pass in URLs containing an existing connection's base_url" do
|
data/spec/lib/connection_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveRestClient::Connection do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@connection = ActiveRestClient::Connection.new("http://www.example.com")
|
6
6
|
end
|
7
7
|
|
@@ -30,7 +30,7 @@ describe ActiveRestClient::Connection do
|
|
30
30
|
|
31
31
|
it "should pass a PUT request through to Patron" do
|
32
32
|
@connection.session = double(Patron::Session)
|
33
|
-
@connection.session.
|
33
|
+
allow(@connection.session).to receive(:put).with("/foo", "body", {}).and_return(OpenStruct.new(body:"{result:true}"))
|
34
34
|
result = @connection.put("/foo", "body")
|
35
35
|
expect(result.body).to eq("{result:true}")
|
36
36
|
end
|
data/spec/lib/proxy_spec.rb
CHANGED
@@ -126,15 +126,24 @@ describe ActiveRestClient::Base do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
it "caches responses in the standard way" do
|
129
|
+
|
130
|
+
cached_response = ActiveRestClient::CachedResponse.new(
|
131
|
+
status:200,
|
132
|
+
result:@cached_object,
|
133
|
+
etag:@etag)
|
134
|
+
|
129
135
|
cache_store = double("CacheStore")
|
130
136
|
cache_store.stub(:read).with(any_args).and_return(nil)
|
131
|
-
|
137
|
+
ProxyClientExample.perform_caching true
|
138
|
+
ProxyClientExample.stub(:cache_store).and_return(cache_store)
|
132
139
|
expiry = 10.minutes.from_now.rfc2822
|
133
140
|
ActiveRestClient::Connection.any_instance.should_receive(:put).with("/update", "MY-BODY-CONTENT", instance_of(Hash)).and_return(OpenStruct.new(body:"{\"result\":true}", status:200, headers:{"Expires" => expiry, "ETag" => "123456"}))
|
134
|
-
|
141
|
+
ProxyClientExample.cache_store.should_receive(:write) do |key, object, options|
|
135
142
|
expect(key).to eq("ProxyClientExample:/update")
|
136
|
-
expect(object
|
137
|
-
|
143
|
+
expect(object).to be_an_instance_of(String)
|
144
|
+
unmarshalled = Marshal.load(object)
|
145
|
+
expect(unmarshalled.etag).to eq("123456")
|
146
|
+
expect(unmarshalled.expires).to eq(expiry)
|
138
147
|
end
|
139
148
|
ProxyClientExample.update(id:1)
|
140
149
|
end
|
data/spec/lib/request_spec.rb
CHANGED
@@ -188,7 +188,7 @@ describe ActiveRestClient::Request do
|
|
188
188
|
with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
|
189
189
|
and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
|
190
190
|
ActiveRestClient::Logger.should_receive(:info).with {|*args| args.first[%r{Requesting http://www.example.com/create}]}
|
191
|
-
ActiveRestClient::Logger.should_receive(:debug).with {|*args| args.first[/Response received \d+ bytes/]}
|
191
|
+
ActiveRestClient::Logger.should_receive(:debug).at_least(1).times.with {|*args| args.first[/Response received \d+ bytes/] || args.first["Reading from cache"]}
|
192
192
|
|
193
193
|
object = ExampleClient.new(first_name:"John", should_disappear:true)
|
194
194
|
object.create
|
@@ -202,7 +202,7 @@ describe ActiveRestClient::Request do
|
|
202
202
|
with("/create", "first_name=John&should_disappear=true", an_instance_of(Hash)).
|
203
203
|
and_return(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", headers:{}, status:200))
|
204
204
|
ActiveRestClient::Logger.should_receive(:info).with {|*args| args.first[%r{Requesting http://www.example.com/create}]}
|
205
|
-
ActiveRestClient::Logger.should_receive(:debug).with {|*args| args.first[/Response received \d+ bytes/]}
|
205
|
+
ActiveRestClient::Logger.should_receive(:debug).at_least(1).times.with {|*args| args.first[/Response received \d+ bytes/] || args.first["Reading from cache"]}
|
206
206
|
|
207
207
|
object = ExampleClient.new(first_name:"John", should_disappear:true)
|
208
208
|
object.create
|
@@ -335,6 +335,7 @@ describe ActiveRestClient::Request do
|
|
335
335
|
end
|
336
336
|
fake_object = RequestFakeObject.new
|
337
337
|
request = ActiveRestClient::Request.new(method, fake_object, {})
|
338
|
+
allow(fake_object).to receive(:read_cached_response).and_return(nil)
|
338
339
|
expect{request.call}.to raise_error(ActiveRestClient::InvalidRequestException)
|
339
340
|
end
|
340
341
|
|
data/spec/spec_helper.rb
CHANGED
@@ -20,3 +20,25 @@ RSpec.configure do |config|
|
|
20
20
|
# --seed 1234
|
21
21
|
config.order = 'random'
|
22
22
|
end
|
23
|
+
|
24
|
+
class TestCacheStore
|
25
|
+
def initialize
|
26
|
+
@items = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def read(key)
|
30
|
+
@items[key]
|
31
|
+
end
|
32
|
+
|
33
|
+
def write(key, value, options={})
|
34
|
+
@items[key] = value
|
35
|
+
end
|
36
|
+
|
37
|
+
def fetch(key, &block)
|
38
|
+
read(key) || begin
|
39
|
+
value = block.call
|
40
|
+
write(value)
|
41
|
+
value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_rest_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.65
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Which Ltd
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|