routemaster-drain 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codecov.yml +29 -0
- data/.travis.yml +1 -3
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -4
- data/Gemfile.lock +10 -7
- data/README.md +1 -8
- data/gemfiles/rails_3.gemfile +4 -4
- data/gemfiles/rails_3.gemfile.lock +7 -4
- data/gemfiles/rails_4.gemfile +4 -4
- data/gemfiles/rails_4.gemfile.lock +7 -4
- data/gemfiles/rails_5.gemfile +4 -4
- data/gemfiles/rails_5.gemfile.lock +7 -4
- data/lib/routemaster/api_client.rb +4 -4
- data/lib/routemaster/cache.rb +1 -1
- data/lib/routemaster/drain.rb +1 -1
- data/lib/routemaster/responses/{future_response.rb → response_promise.rb} +8 -8
- data/spec/routemaster/api_client_spec.rb +48 -0
- data/spec/routemaster/integration/api_client_spec.rb +1 -1
- data/spec/routemaster/responses/hateoas_enumerable_response_spec.rb +4 -4
- data/spec/routemaster/responses/response_promise_spec.rb +29 -0
- data/spec/spec_helper.rb +3 -0
- metadata +7 -6
- data/spec/routemaster/responses/future_response_spec.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b2b697edbd498992119a65a84728e882d7887f4
|
4
|
+
data.tar.gz: becfe51f7378b6ef526f30df85cc0ba99e988506
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97304f92aca0207ed65ebed6448f16da4a95c35b220be95a4397e85642a244fce6ae299cbd613859245b09d3e892b4c60e7c8c4d0ae2a6b2f54bd7bb1ebdccb9
|
7
|
+
data.tar.gz: 5e8b39950919c0d6df02399a1579940a0b8f0c88c7e2c5cd332193e01f683b9201253a267b17a0ecd19e18d050a749ba0f832e37f863e27b74ea8ae526c412d7
|
data/.codecov.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
codecov:
|
2
|
+
notify:
|
3
|
+
require_ci_to_pass: yes
|
4
|
+
|
5
|
+
coverage:
|
6
|
+
precision: 2
|
7
|
+
round: down
|
8
|
+
range: "70...100"
|
9
|
+
|
10
|
+
status:
|
11
|
+
project:
|
12
|
+
default:
|
13
|
+
enabled: yes
|
14
|
+
threshold: 1%
|
15
|
+
patch:
|
16
|
+
default:
|
17
|
+
enabled: yes
|
18
|
+
threshold: 5%
|
19
|
+
changes: no
|
20
|
+
|
21
|
+
parsers:
|
22
|
+
gcov:
|
23
|
+
branch_detection:
|
24
|
+
conditional: yes
|
25
|
+
loop: yes
|
26
|
+
method: no
|
27
|
+
macro: no
|
28
|
+
|
29
|
+
comment: off
|
data/.travis.yml
CHANGED
@@ -12,11 +12,9 @@ gemfile:
|
|
12
12
|
- gemfiles/rails_4.gemfile
|
13
13
|
- gemfiles/rails_5.gemfile
|
14
14
|
script:
|
15
|
-
- bundle exec rspec
|
16
|
-
- bundle exec codeclimate-test-reporter
|
15
|
+
- bundle exec rspec
|
17
16
|
matrix:
|
18
17
|
allow_failures:
|
19
18
|
- rvm: ruby-head
|
20
19
|
- rvm: 2.4.0
|
21
20
|
gemfile: gemfiles/rails_3.gemfile
|
22
|
-
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -12,10 +12,10 @@ gem 'rake', require: false
|
|
12
12
|
gem 'webmock', require: false
|
13
13
|
gem 'rack-test', require: false
|
14
14
|
gem 'dotenv', require: false
|
15
|
-
gem '
|
16
|
-
gem '
|
17
|
-
gem 'resque'
|
18
|
-
gem 'sidekiq'
|
15
|
+
gem 'simplecov', require: false
|
16
|
+
gem 'codecov', require: false
|
17
|
+
gem 'resque', require: false
|
18
|
+
gem 'sidekiq', require: false
|
19
19
|
|
20
20
|
gem 'guard-rspec', require: false
|
21
21
|
gem 'pry', require: false
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
routemaster-drain (2.4.
|
4
|
+
routemaster-drain (2.4.1)
|
5
5
|
concurrent-ruby
|
6
6
|
faraday (>= 0.9.0)
|
7
7
|
faraday_middleware
|
@@ -21,8 +21,10 @@ GEM
|
|
21
21
|
rake
|
22
22
|
thor (>= 0.14.0)
|
23
23
|
byebug (9.0.6)
|
24
|
-
|
24
|
+
codecov (0.1.9)
|
25
|
+
json
|
25
26
|
simplecov
|
27
|
+
url
|
26
28
|
coderay (1.1.1)
|
27
29
|
concurrent-ruby (1.0.5)
|
28
30
|
connection_pool (2.2.1)
|
@@ -58,8 +60,8 @@ GEM
|
|
58
60
|
guard-compat (~> 1.1)
|
59
61
|
rspec (>= 2.99.0, < 4.0)
|
60
62
|
hashdiff (0.3.2)
|
61
|
-
hashie (3.
|
62
|
-
json (2.0.
|
63
|
+
hashie (3.5.5)
|
64
|
+
json (2.0.3)
|
63
65
|
listen (3.1.5)
|
64
66
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
65
67
|
rb-inotify (~> 0.9, >= 0.9.7)
|
@@ -118,7 +120,7 @@ GEM
|
|
118
120
|
connection_pool (~> 2.2, >= 2.2.0)
|
119
121
|
rack-protection (>= 1.5.0)
|
120
122
|
redis (~> 3.2, >= 3.2.1)
|
121
|
-
simplecov (0.
|
123
|
+
simplecov (0.13.0)
|
122
124
|
docile (~> 1.1.0)
|
123
125
|
json (>= 1.8, < 3)
|
124
126
|
simplecov-html (~> 0.10.0)
|
@@ -132,6 +134,7 @@ GEM
|
|
132
134
|
tilt (2.0.5)
|
133
135
|
typhoeus (1.1.2)
|
134
136
|
ethon (>= 0.9.0)
|
137
|
+
url (0.3.2)
|
135
138
|
vegas (0.1.11)
|
136
139
|
rack (>= 1.0.0)
|
137
140
|
webmock (2.3.2)
|
@@ -147,7 +150,7 @@ DEPENDENCIES
|
|
147
150
|
appraisal
|
148
151
|
bundler
|
149
152
|
byebug
|
150
|
-
|
153
|
+
codecov
|
151
154
|
dogstatsd
|
152
155
|
dotenv
|
153
156
|
fork_break
|
@@ -164,4 +167,4 @@ DEPENDENCIES
|
|
164
167
|
webmock
|
165
168
|
|
166
169
|
BUNDLED WITH
|
167
|
-
1.14.
|
170
|
+
1.14.6
|
data/README.md
CHANGED
@@ -1,15 +1,8 @@
|
|
1
|
-
# routemaster-drain
|
1
|
+
# routemaster-drain [![Version](https://badge.fury.io/rb/routemaster-drain.svg)](https://rubygems.org/gems/routemaster-drain) [![Build](https://travis-ci.org/deliveroo/routemaster-drain.svg?branch=master)](https://travis-ci.org/deliveroo/routemaster-drain) [![Code Climate](https://codeclimate.com/github/deliveroo/routemaster-drain/badges/gpa.svg)](https://codeclimate.com/github/deliveroo/routemaster-drain) [![codecov](https://codecov.io/gh/deliveroo/routemaster-drain/branch/master/graph/badge.svg)](https://codecov.io/gh/deliveroo/routemaster-drain) [![Docs](http://img.shields.io/badge/API%20docs-rubydoc.info-blue.svg)](http://rubydoc.info/github/deliveroo/routemaster-drain)
|
2
2
|
|
3
3
|
A Rack-based event receiver for the
|
4
4
|
[Routemaster](https://github.com/deliveroo/routemaster) event bus.
|
5
5
|
|
6
|
-
[![Version](https://badge.fury.io/rb/routemaster-drain.svg)](https://rubygems.org/gems/routemaster-drain)
|
7
|
-
|
8
|
-
[![Build](https://travis-ci.org/deliveroo/routemaster-drain.svg?branch=master)](https://travis-ci.org/deliveroo/routemaster-drain)
|
9
|
-
|
10
|
-
[![Code Climate](https://codeclimate.com/github/deliveroo/routemaster-drain/badges/gpa.svg)](https://codeclimate.com/github/deliveroo/routemaster-drain)
|
11
|
-
[![Test Coverage](https://codeclimate.com/github/deliveroo/routemaster-drain/badges/coverage.svg)](https://codeclimate.com/github/deliveroo/routemaster-drain/coverage)
|
12
|
-
[![Docs](http://img.shields.io/badge/API%20docs-rubydoc.info-blue.svg)](http://rubydoc.info/github/deliveroo/routemaster-drain)
|
13
6
|
|
14
7
|
`routemaster-drain` is a collection of Rack middleware to receive and
|
15
8
|
parse Routemaster events, filter them, and preemptively cache the corresponding
|
data/gemfiles/rails_3.gemfile
CHANGED
@@ -8,10 +8,10 @@ gem "rake", :require => false
|
|
8
8
|
gem "webmock", :require => false
|
9
9
|
gem "rack-test", :require => false
|
10
10
|
gem "dotenv", :require => false
|
11
|
-
gem "
|
12
|
-
gem "
|
13
|
-
gem "resque"
|
14
|
-
gem "sidekiq"
|
11
|
+
gem "simplecov", :require => false
|
12
|
+
gem "codecov", :require => false
|
13
|
+
gem "resque", :require => false
|
14
|
+
gem "sidekiq", :require => false
|
15
15
|
gem "guard-rspec", :require => false
|
16
16
|
gem "pry", :require => false
|
17
17
|
gem "byebug", :require => false
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
routemaster-drain (2.4.
|
4
|
+
routemaster-drain (2.4.1)
|
5
5
|
concurrent-ruby
|
6
6
|
faraday (>= 0.9.0)
|
7
7
|
faraday_middleware
|
@@ -50,8 +50,10 @@ GEM
|
|
50
50
|
arel (3.0.3)
|
51
51
|
builder (3.0.4)
|
52
52
|
byebug (9.0.6)
|
53
|
-
|
53
|
+
codecov (0.1.9)
|
54
|
+
json
|
54
55
|
simplecov
|
56
|
+
url
|
55
57
|
coderay (1.1.1)
|
56
58
|
concurrent-ruby (1.0.5)
|
57
59
|
connection_pool (2.2.1)
|
@@ -88,7 +90,7 @@ GEM
|
|
88
90
|
guard-compat (~> 1.1)
|
89
91
|
rspec (>= 2.99.0, < 4.0)
|
90
92
|
hashdiff (0.3.2)
|
91
|
-
hashie (3.
|
93
|
+
hashie (3.5.5)
|
92
94
|
hike (1.2.3)
|
93
95
|
i18n (0.8.1)
|
94
96
|
journey (1.0.4)
|
@@ -200,6 +202,7 @@ GEM
|
|
200
202
|
typhoeus (1.1.2)
|
201
203
|
ethon (>= 0.9.0)
|
202
204
|
tzinfo (0.3.52)
|
205
|
+
url (0.3.2)
|
203
206
|
vegas (0.1.11)
|
204
207
|
rack (>= 1.0.0)
|
205
208
|
webmock (2.3.2)
|
@@ -215,7 +218,7 @@ DEPENDENCIES
|
|
215
218
|
appraisal
|
216
219
|
bundler
|
217
220
|
byebug
|
218
|
-
|
221
|
+
codecov
|
219
222
|
dogstatsd
|
220
223
|
dotenv
|
221
224
|
fork_break
|
data/gemfiles/rails_4.gemfile
CHANGED
@@ -8,10 +8,10 @@ gem "rake", :require => false
|
|
8
8
|
gem "webmock", :require => false
|
9
9
|
gem "rack-test", :require => false
|
10
10
|
gem "dotenv", :require => false
|
11
|
-
gem "
|
12
|
-
gem "
|
13
|
-
gem "resque"
|
14
|
-
gem "sidekiq"
|
11
|
+
gem "simplecov", :require => false
|
12
|
+
gem "codecov", :require => false
|
13
|
+
gem "resque", :require => false
|
14
|
+
gem "sidekiq", :require => false
|
15
15
|
gem "guard-rspec", :require => false
|
16
16
|
gem "pry", :require => false
|
17
17
|
gem "byebug", :require => false
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
routemaster-drain (2.4.
|
4
|
+
routemaster-drain (2.4.1)
|
5
5
|
concurrent-ruby
|
6
6
|
faraday (>= 0.9.0)
|
7
7
|
faraday_middleware
|
@@ -57,8 +57,10 @@ GEM
|
|
57
57
|
arel (6.0.4)
|
58
58
|
builder (3.2.3)
|
59
59
|
byebug (9.0.6)
|
60
|
-
|
60
|
+
codecov (0.1.9)
|
61
|
+
json
|
61
62
|
simplecov
|
63
|
+
url
|
62
64
|
coderay (1.1.1)
|
63
65
|
concurrent-ruby (1.0.5)
|
64
66
|
connection_pool (2.2.1)
|
@@ -97,7 +99,7 @@ GEM
|
|
97
99
|
guard-compat (~> 1.1)
|
98
100
|
rspec (>= 2.99.0, < 4.0)
|
99
101
|
hashdiff (0.3.2)
|
100
|
-
hashie (3.
|
102
|
+
hashie (3.5.5)
|
101
103
|
i18n (0.8.1)
|
102
104
|
json (2.0.3)
|
103
105
|
listen (3.1.5)
|
@@ -217,6 +219,7 @@ GEM
|
|
217
219
|
ethon (>= 0.9.0)
|
218
220
|
tzinfo (1.2.2)
|
219
221
|
thread_safe (~> 0.1)
|
222
|
+
url (0.3.2)
|
220
223
|
vegas (0.1.11)
|
221
224
|
rack (>= 1.0.0)
|
222
225
|
webmock (2.3.2)
|
@@ -232,7 +235,7 @@ DEPENDENCIES
|
|
232
235
|
appraisal
|
233
236
|
bundler
|
234
237
|
byebug
|
235
|
-
|
238
|
+
codecov
|
236
239
|
dogstatsd
|
237
240
|
dotenv
|
238
241
|
fork_break
|
data/gemfiles/rails_5.gemfile
CHANGED
@@ -8,10 +8,10 @@ gem "rake", :require => false
|
|
8
8
|
gem "webmock", :require => false
|
9
9
|
gem "rack-test", :require => false
|
10
10
|
gem "dotenv", :require => false
|
11
|
-
gem "
|
12
|
-
gem "
|
13
|
-
gem "resque"
|
14
|
-
gem "sidekiq"
|
11
|
+
gem "simplecov", :require => false
|
12
|
+
gem "codecov", :require => false
|
13
|
+
gem "resque", :require => false
|
14
|
+
gem "sidekiq", :require => false
|
15
15
|
gem "guard-rspec", :require => false
|
16
16
|
gem "pry", :require => false
|
17
17
|
gem "byebug", :require => false
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
routemaster-drain (2.4.
|
4
|
+
routemaster-drain (2.4.1)
|
5
5
|
concurrent-ruby
|
6
6
|
faraday (>= 0.9.0)
|
7
7
|
faraday_middleware
|
@@ -60,8 +60,10 @@ GEM
|
|
60
60
|
arel (7.1.4)
|
61
61
|
builder (3.2.3)
|
62
62
|
byebug (9.0.6)
|
63
|
-
|
63
|
+
codecov (0.1.9)
|
64
|
+
json
|
64
65
|
simplecov
|
66
|
+
url
|
65
67
|
coderay (1.1.1)
|
66
68
|
concurrent-ruby (1.0.5)
|
67
69
|
connection_pool (2.2.1)
|
@@ -100,7 +102,7 @@ GEM
|
|
100
102
|
guard-compat (~> 1.1)
|
101
103
|
rspec (>= 2.99.0, < 4.0)
|
102
104
|
hashdiff (0.3.2)
|
103
|
-
hashie (3.
|
105
|
+
hashie (3.5.5)
|
104
106
|
i18n (0.8.1)
|
105
107
|
json (2.0.3)
|
106
108
|
listen (3.1.5)
|
@@ -217,6 +219,7 @@ GEM
|
|
217
219
|
ethon (>= 0.9.0)
|
218
220
|
tzinfo (1.2.2)
|
219
221
|
thread_safe (~> 0.1)
|
222
|
+
url (0.3.2)
|
220
223
|
vegas (0.1.11)
|
221
224
|
rack (>= 1.0.0)
|
222
225
|
webmock (2.3.2)
|
@@ -235,7 +238,7 @@ DEPENDENCIES
|
|
235
238
|
appraisal
|
236
239
|
bundler
|
237
240
|
byebug
|
238
|
-
|
241
|
+
codecov
|
239
242
|
dogstatsd
|
240
243
|
dotenv
|
241
244
|
fork_break
|
@@ -7,7 +7,7 @@ require 'routemaster/config'
|
|
7
7
|
require 'routemaster/middleware/response_caching'
|
8
8
|
require 'routemaster/middleware/error_handling'
|
9
9
|
require 'routemaster/middleware/metrics'
|
10
|
-
require 'routemaster/responses/
|
10
|
+
require 'routemaster/responses/response_promise'
|
11
11
|
|
12
12
|
# Loading the Faraday adapter for Typhoeus requires a little dance
|
13
13
|
require 'faraday/adapter/typhoeus'
|
@@ -49,16 +49,16 @@ module Routemaster
|
|
49
49
|
enable_caching = options.fetch(:enable_caching, true)
|
50
50
|
|
51
51
|
_wrapped_response _request(
|
52
|
-
:get,
|
52
|
+
:get,
|
53
53
|
url: url,
|
54
54
|
params: params,
|
55
55
|
headers: headers.merge(response_cache_opt_headers(enable_caching)))
|
56
56
|
end
|
57
57
|
|
58
|
-
# Same as {{get}}, except with
|
58
|
+
# Same as {{get}}, except with
|
59
59
|
def fget(url, **options)
|
60
60
|
uri = _assert_uri(url)
|
61
|
-
Responses::
|
61
|
+
Responses::ResponsePromise.new { get(uri, options) }
|
62
62
|
end
|
63
63
|
|
64
64
|
def post(url, body: {}, headers: {})
|
data/lib/routemaster/cache.rb
CHANGED
@@ -55,7 +55,7 @@ module Routemaster
|
|
55
55
|
# Like {#get}, but schedules any request in the background using a thread
|
56
56
|
# pool. Handy to issue lots of requests in parallel.
|
57
57
|
#
|
58
|
-
# @return [
|
58
|
+
# @return [ResponsePromise], which responds to `status`, `headers`, and `body`
|
59
59
|
# like [Response].
|
60
60
|
def fget(url, version: nil, locale: nil)
|
61
61
|
@client.fget(url, headers: headers(version: version, locale: locale))
|
data/lib/routemaster/drain.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'concurrent/
|
1
|
+
require 'concurrent/promise'
|
2
2
|
require 'concurrent/executor/cached_thread_pool'
|
3
3
|
require 'singleton'
|
4
4
|
require 'delegate'
|
5
5
|
|
6
6
|
module Routemaster
|
7
7
|
module Responses
|
8
|
-
class
|
8
|
+
class ResponsePromise
|
9
9
|
extend Forwardable
|
10
10
|
|
11
11
|
# The `block` is expected to return a {Response}
|
12
12
|
def initialize(&block)
|
13
|
-
@
|
13
|
+
@promise = Concurrent::Promise.execute(executor: Pool.current, &block)
|
14
14
|
end
|
15
15
|
|
16
16
|
# @!attribute status
|
@@ -24,18 +24,18 @@ module Routemaster
|
|
24
24
|
# @!attribute body
|
25
25
|
# @return [Hashie::Mash]
|
26
26
|
# Delegated to the `block`'s return value.
|
27
|
-
|
28
|
-
delegate :value => :@future
|
29
27
|
delegate %i(status headers body) => :value
|
28
|
+
delegate %i(on_success on_error execute state) => :@promise
|
29
|
+
|
30
30
|
delegate :respond_to_missing? => :value
|
31
|
-
|
31
|
+
|
32
32
|
def method_missing(m, *args, &block)
|
33
33
|
value.public_send(m, *args, &block)
|
34
34
|
end
|
35
35
|
|
36
36
|
def value
|
37
|
-
@
|
38
|
-
raise @
|
37
|
+
@promise.value.tap do
|
38
|
+
raise @promise.reason if @promise.rejected?
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -80,6 +80,54 @@ describe Routemaster::APIClient do
|
|
80
80
|
describe '#fget' do
|
81
81
|
subject { fetcher.fget(url, headers: headers) }
|
82
82
|
it_behaves_like 'a GET requester'
|
83
|
+
|
84
|
+
context "when setting callbacks" do
|
85
|
+
before do
|
86
|
+
stub_request(:get, /example\.com/).to_return(
|
87
|
+
status: status,
|
88
|
+
body: { id: 132, type: 'widget' }.to_json,
|
89
|
+
headers: {
|
90
|
+
'content-type' => 'application/json;v=1'
|
91
|
+
}
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
let(:callback_spy) { spy('callback_spy') }
|
96
|
+
|
97
|
+
subject do
|
98
|
+
fetcher.fget(url, headers: headers)
|
99
|
+
end
|
100
|
+
|
101
|
+
let(:callback){
|
102
|
+
subject.on_success do
|
103
|
+
callback_spy.success
|
104
|
+
end
|
105
|
+
subject.on_error do
|
106
|
+
callback_spy.error
|
107
|
+
end
|
108
|
+
}
|
109
|
+
|
110
|
+
context "when successful" do
|
111
|
+
let(:status){ 200 }
|
112
|
+
it "calls on_success" do
|
113
|
+
expect(subject.status).to eq 200
|
114
|
+
callback.value #We need to wait before testing if the spy was called
|
115
|
+
expect(callback_spy).to have_received(:success)
|
116
|
+
expect(callback_spy).not_to have_received(:error)
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when not successful" do
|
122
|
+
let(:status){ 500 }
|
123
|
+
it "calls on_error" do
|
124
|
+
expect{subject.value}.to raise_error { Routemaster::Errors::FatalResource }
|
125
|
+
callback.value #We need to wait before testing if the spy was called
|
126
|
+
expect(callback_spy).to have_received(:error)
|
127
|
+
expect(callback_spy).not_to have_received(:success)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
83
131
|
end
|
84
132
|
|
85
133
|
describe '#post' do
|
@@ -158,7 +158,7 @@ describe Routemaster::APIClient do
|
|
158
158
|
expect { perform.(host + '/500') }.to raise_error(Routemaster::Errors::FatalResource)
|
159
159
|
end
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
describe '#get' do
|
163
163
|
let(:perform) { ->(uri) { subject.get(uri) } }
|
164
164
|
include_examples 'exception raiser'
|
@@ -18,9 +18,9 @@ describe Routemaster::Responses::HateoasEnumerableResponse do
|
|
18
18
|
|
19
19
|
before do
|
20
20
|
@resource_stub = stub_request(:get, resource_tpl).to_return do |req|
|
21
|
-
{
|
22
|
-
status: 200,
|
23
|
-
headers: { 'Content-Type' => 'application/json' },
|
21
|
+
{
|
22
|
+
status: 200,
|
23
|
+
headers: { 'Content-Type' => 'application/json' },
|
24
24
|
body: {
|
25
25
|
id: req.uri.path.split('/').last.to_i,
|
26
26
|
_links: {
|
@@ -59,7 +59,7 @@ describe Routemaster::Responses::HateoasEnumerableResponse do
|
|
59
59
|
subject { described_class.new(client.get(index_url)) }
|
60
60
|
|
61
61
|
# so we don't pollute future specs with pending requests:
|
62
|
-
after { Routemaster::Responses::
|
62
|
+
after { Routemaster::Responses::ResponsePromise::Pool.reset }
|
63
63
|
|
64
64
|
describe '#each' do
|
65
65
|
it 'is enumerable' do
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'hashie/mash'
|
3
|
+
require 'routemaster/responses/response_promise'
|
4
|
+
|
5
|
+
describe Routemaster::Responses::ResponsePromise do
|
6
|
+
%i[status headers body].each do |method|
|
7
|
+
it "passes through '#{method}'" do
|
8
|
+
promise = described_class.new { Hashie::Mash.new(method => 'foobar') }
|
9
|
+
promise.execute
|
10
|
+
expect(promise.public_send(method)).to eq('foobar')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can have callbacks set" do
|
15
|
+
passing_spy = spy('passing spy')
|
16
|
+
promise = described_class.new { }
|
17
|
+
success_promise = promise.on_success { passing_spy.on_success }
|
18
|
+
promise.execute
|
19
|
+
promise.value
|
20
|
+
success_promise.value
|
21
|
+
expect(passing_spy).to have_received(:on_success)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 're-raises exceptions' do
|
25
|
+
promise = described_class.new { raise 'foobar' }
|
26
|
+
promise.execute
|
27
|
+
expect { promise.status }.to raise_error(RuntimeError, 'foobar')
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.1
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -130,6 +130,7 @@ extensions: []
|
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
132
|
- ".codeclimate.yml"
|
133
|
+
- ".codecov.yml"
|
133
134
|
- ".env.test"
|
134
135
|
- ".gitignore"
|
135
136
|
- ".gitmodules"
|
@@ -187,9 +188,9 @@ files:
|
|
187
188
|
- lib/routemaster/null_logger.rb
|
188
189
|
- lib/routemaster/redis_broker.rb
|
189
190
|
- lib/routemaster/resources/rest_resource.rb
|
190
|
-
- lib/routemaster/responses/future_response.rb
|
191
191
|
- lib/routemaster/responses/hateoas_enumerable_response.rb
|
192
192
|
- lib/routemaster/responses/hateoas_response.rb
|
193
|
+
- lib/routemaster/responses/response_promise.rb
|
193
194
|
- routemaster-drain.gemspec
|
194
195
|
- spec/routemaster/api_client_spec.rb
|
195
196
|
- spec/routemaster/cache_spec.rb
|
@@ -215,9 +216,9 @@ files:
|
|
215
216
|
- spec/routemaster/middleware/root_post_only_spec.rb
|
216
217
|
- spec/routemaster/redis_broker_spec.rb
|
217
218
|
- spec/routemaster/resources/rest_resource_spec.rb
|
218
|
-
- spec/routemaster/responses/future_response_spec.rb
|
219
219
|
- spec/routemaster/responses/hateoas_enumerable_response_spec.rb
|
220
220
|
- spec/routemaster/responses/hateoas_response_spec.rb
|
221
|
+
- spec/routemaster/responses/response_promise_spec.rb
|
221
222
|
- spec/spec_helper.rb
|
222
223
|
- spec/support/breakpoint_class.rb
|
223
224
|
- spec/support/events.rb
|
@@ -246,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
246
247
|
version: '0'
|
247
248
|
requirements: []
|
248
249
|
rubyforge_project:
|
249
|
-
rubygems_version: 2.
|
250
|
+
rubygems_version: 2.5.2
|
250
251
|
signing_key:
|
251
252
|
specification_version: 4
|
252
253
|
summary: Event receiver for the Routemaster bus
|
@@ -275,9 +276,9 @@ test_files:
|
|
275
276
|
- spec/routemaster/middleware/root_post_only_spec.rb
|
276
277
|
- spec/routemaster/redis_broker_spec.rb
|
277
278
|
- spec/routemaster/resources/rest_resource_spec.rb
|
278
|
-
- spec/routemaster/responses/future_response_spec.rb
|
279
279
|
- spec/routemaster/responses/hateoas_enumerable_response_spec.rb
|
280
280
|
- spec/routemaster/responses/hateoas_response_spec.rb
|
281
|
+
- spec/routemaster/responses/response_promise_spec.rb
|
281
282
|
- spec/spec_helper.rb
|
282
283
|
- spec/support/breakpoint_class.rb
|
283
284
|
- spec/support/events.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'hashie/mash'
|
3
|
-
require 'routemaster/responses/future_response'
|
4
|
-
|
5
|
-
describe Routemaster::Responses::FutureResponse do
|
6
|
-
%i[status headers body].each do |method|
|
7
|
-
it "passes through '#{method}'" do
|
8
|
-
future = described_class.new { Hashie::Mash.new(method => 'foobar') }
|
9
|
-
expect(future.public_send(method)).to eq('foobar')
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
it 're-raises exceptions' do
|
14
|
-
future = described_class.new { raise 'foobar' }
|
15
|
-
|
16
|
-
expect { future.status }.to raise_error(RuntimeError, 'foobar')
|
17
|
-
end
|
18
|
-
end
|