routemaster-drain 2.4.1 → 2.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b2b697edbd498992119a65a84728e882d7887f4
4
- data.tar.gz: becfe51f7378b6ef526f30df85cc0ba99e988506
3
+ metadata.gz: 07bdffea2f172347e8aca46c2f75dab8634447ee
4
+ data.tar.gz: f44e9ef9b5aeaf94603639fa29d6d2e25b787be2
5
5
  SHA512:
6
- metadata.gz: 97304f92aca0207ed65ebed6448f16da4a95c35b220be95a4397e85642a244fce6ae299cbd613859245b09d3e892b4c60e7c8c4d0ae2a6b2f54bd7bb1ebdccb9
7
- data.tar.gz: 5e8b39950919c0d6df02399a1579940a0b8f0c88c7e2c5cd332193e01f683b9201253a267b17a0ecd19e18d050a749ba0f832e37f863e27b74ea8ae526c412d7
6
+ metadata.gz: 797d4f36d492a81ca180237eca1f0e8a0124f6e5f0a6445ca1f769f0b9ec9023f54d507f3f9b73a00370b383ef926758e528fe02fdb6403246945202ed7ddfa1
7
+ data.tar.gz: 672da230fb723af0edd3ed714316272919d0ecf20159497200a3fb78a4bb39ee8d594dcab2b024f72d55f931a8d8d9174343e636fb08906365eaa4a01626bc7f
@@ -1,3 +1,9 @@
1
+ ### 2.4.2 (2017-03-21)
2
+
3
+ Bug fixes:
4
+
5
+ - APIClient#discover now memoizes the root response at class level (#35)
6
+
1
7
  ### 2.4.1 (2017-03-15)
2
8
 
3
9
  Features:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- routemaster-drain (2.4.1)
4
+ routemaster-drain (2.4.2)
5
5
  concurrent-ruby
6
6
  faraday (>= 0.9.0)
7
7
  faraday_middleware
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routemaster-drain (2.4.1)
4
+ routemaster-drain (2.4.2)
5
5
  concurrent-ruby
6
6
  faraday (>= 0.9.0)
7
7
  faraday_middleware
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routemaster-drain (2.4.1)
4
+ routemaster-drain (2.4.2)
5
5
  concurrent-ruby
6
6
  faraday (>= 0.9.0)
7
7
  faraday_middleware
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routemaster-drain (2.4.1)
4
+ routemaster-drain (2.4.2)
5
5
  concurrent-ruby
6
6
  faraday (>= 0.9.0)
7
7
  faraday_middleware
@@ -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
- @listener = listener
34
- @middlewares = middlewares
38
+
39
+ @listener = listener
40
+ @middlewares = middlewares
35
41
  @response_class = response_class
36
42
  @metrics_client = metrics_client
37
- @source_peer = 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)
@@ -1,5 +1,5 @@
1
1
  module Routemaster
2
2
  module Drain
3
- VERSION = '2.4.1'
3
+ VERSION = '2.4.2'
4
4
  end
5
5
  end
@@ -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 any if just the index method is called' do
304
- resources = subject.discover(url).resources
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
- expect(subject).to receive(:get).with("http://localhost:#{port}/resources", anything).once
307
- resources.index
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.1
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-15 00:00:00.000000000 Z
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.5.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