routemaster-drain 2.4.1 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/gemfiles/rails_3.gemfile.lock +1 -1
- data/gemfiles/rails_4.gemfile.lock +1 -1
- data/gemfiles/rails_5.gemfile.lock +1 -1
- data/lib/routemaster/api_client.rb +10 -4
- data/lib/routemaster/drain.rb +1 -1
- data/spec/routemaster/integration/api_client_spec.rb +34 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07bdffea2f172347e8aca46c2f75dab8634447ee
|
4
|
+
data.tar.gz: f44e9ef9b5aeaf94603639fa29d6d2e25b787be2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 797d4f36d492a81ca180237eca1f0e8a0124f6e5f0a6445ca1f769f0b9ec9023f54d507f3f9b73a00370b383ef926758e528fe02fdb6403246945202ed7ddfa1
|
7
|
+
data.tar.gz: 672da230fb723af0edd3ed714316272919d0ecf20159497200a3fb78a4bb39ee8d594dcab2b024f72d55f931a8d8d9174343e636fb08906365eaa4a01626bc7f
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -25,16 +25,22 @@ require 'hashie/mash'
|
|
25
25
|
|
26
26
|
module Routemaster
|
27
27
|
class APIClient
|
28
|
+
|
29
|
+
# Memoize the root resources at Class level so that we don't hit the cache
|
30
|
+
# all the time to fetch the root resource before doing anything else.
|
31
|
+
@@root_resources = {}
|
32
|
+
|
28
33
|
def initialize(middlewares: [],
|
29
34
|
listener: nil,
|
30
35
|
response_class: nil,
|
31
36
|
metrics_client: nil,
|
32
37
|
source_peer: nil)
|
33
|
-
|
34
|
-
@
|
38
|
+
|
39
|
+
@listener = listener
|
40
|
+
@middlewares = middlewares
|
35
41
|
@response_class = response_class
|
36
42
|
@metrics_client = metrics_client
|
37
|
-
@source_peer
|
43
|
+
@source_peer = source_peer
|
38
44
|
|
39
45
|
connection # warm up connection so Faraday does all it's magical file loading in the main thread
|
40
46
|
end
|
@@ -74,7 +80,7 @@ module Routemaster
|
|
74
80
|
end
|
75
81
|
|
76
82
|
def discover(url)
|
77
|
-
get(url)
|
83
|
+
@@root_resources[url] ||= get(url)
|
78
84
|
end
|
79
85
|
|
80
86
|
def with_response(response_class)
|
data/lib/routemaster/drain.rb
CHANGED
@@ -5,6 +5,7 @@ require 'spec/support/uses_webmock'
|
|
5
5
|
require 'spec/support/server'
|
6
6
|
require 'spec/support/breakpoint_class'
|
7
7
|
require 'routemaster/api_client'
|
8
|
+
require 'routemaster/resources/rest_resource'
|
8
9
|
require 'routemaster/cache'
|
9
10
|
require 'dogstatsd'
|
10
11
|
|
@@ -297,14 +298,43 @@ describe Routemaster::APIClient do
|
|
297
298
|
|
298
299
|
it 'traverses through pagination next all links that match the request params' do
|
299
300
|
res = subject.discover(url)
|
301
|
+
|
300
302
|
expect(res.resources.index(filters: { first_name: 'roo' }).count).to eq(5)
|
301
303
|
end
|
302
304
|
|
303
|
-
it 'does not make any http requests to fetch resources
|
304
|
-
|
305
|
+
it 'does not make any http requests to fetch individual resources if just the index method is called' do
|
306
|
+
res = subject.discover(url)
|
307
|
+
|
308
|
+
expect(subject).not_to receive(:get).with("http://localhost:#{port}/resources/#{anything}", anything)
|
309
|
+
res.resources.index
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
describe 'DISCOVER request' do
|
314
|
+
let(:url) { "http://localhost:#{port}/discover" }
|
305
315
|
|
306
|
-
|
307
|
-
|
316
|
+
subject do
|
317
|
+
Routemaster::APIClient.new(response_class: Routemaster::Responses::HateoasResponse)
|
318
|
+
end
|
319
|
+
|
320
|
+
before { subject.class.class_variable_set :@@root_resources, {} }
|
321
|
+
|
322
|
+
context 'when the method is called for the first time' do
|
323
|
+
it 'fetches the information using the GET method' do
|
324
|
+
expect(subject).to receive(:get).with(url)
|
325
|
+
|
326
|
+
subject.discover(url)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
context 'when the method is called for the n-th time' do
|
331
|
+
before { subject.discover(url) }
|
332
|
+
|
333
|
+
it 'fetches the information from the class variable' do
|
334
|
+
expect(subject).not_to receive(:get).with(url)
|
335
|
+
|
336
|
+
subject.discover(url)
|
337
|
+
end
|
308
338
|
end
|
309
339
|
end
|
310
340
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: routemaster-drain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Letessier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -247,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
247
|
version: '0'
|
248
248
|
requirements: []
|
249
249
|
rubyforge_project:
|
250
|
-
rubygems_version: 2.
|
250
|
+
rubygems_version: 2.6.8
|
251
251
|
signing_key:
|
252
252
|
specification_version: 4
|
253
253
|
summary: Event receiver for the Routemaster bus
|