hyperclient 0.8.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +14 -42
- data/.travis.yml +10 -13
- data/CHANGELOG.md +61 -18
- data/Dangerfile +2 -2
- data/Gemfile +10 -7
- data/LICENSE +1 -1
- data/README.md +47 -36
- data/Rakefile +2 -8
- data/UPGRADING.md +16 -0
- data/features/api_navigation.feature +5 -0
- data/features/steps/api_navigation.rb +17 -4
- data/features/steps/default_config.rb +3 -3
- data/features/support/api.rb +8 -2
- data/features/support/fixtures.rb +96 -2
- data/hyperclient.gemspec +4 -8
- data/lib/hyperclient/collection.rb +1 -1
- data/lib/hyperclient/curie.rb +2 -1
- data/lib/hyperclient/entry_point.rb +15 -9
- data/lib/hyperclient/link.rb +31 -15
- data/lib/hyperclient/link_collection.rb +3 -1
- data/lib/hyperclient/resource.rb +35 -6
- data/lib/hyperclient/resource_collection.rb +3 -1
- data/lib/hyperclient/version.rb +1 -1
- data/test/fixtures/element.json +15 -15
- data/test/hyperclient/attributes_test.rb +9 -9
- data/test/hyperclient/collection_test.rb +15 -15
- data/test/hyperclient/curie_test.rb +4 -4
- data/test/hyperclient/entry_point_test.rb +44 -53
- data/test/hyperclient/link_collection_test.rb +15 -15
- data/test/hyperclient/link_test.rb +53 -239
- data/test/hyperclient/resource_collection_test.rb +6 -6
- data/test/hyperclient/resource_test.rb +40 -24
- data/test/hyperclient_test.rb +9 -10
- data/test/test_helper.rb +8 -9
- metadata +33 -58
- data/lib/faraday/connection.rb +0 -17
- data/test/faraday/connection_test.rb +0 -29
@@ -14,33 +14,33 @@ module Hyperclient
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'is a collection' do
|
17
|
-
LinkCollection.ancestors.must_include Collection
|
17
|
+
_(LinkCollection.ancestors).must_include Collection
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'initializes the collection with links' do
|
21
|
-
links.must_respond_to :
|
22
|
-
links.must_respond_to :gizmos
|
21
|
+
_(links).must_respond_to :search
|
22
|
+
_(links).must_respond_to :gizmos
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'returns link objects for each link' do
|
26
|
-
links.
|
27
|
-
links['self'].must_be_kind_of Link
|
26
|
+
_(links.search).must_be_kind_of Link
|
27
|
+
_(links['self']).must_be_kind_of Link
|
28
28
|
|
29
|
-
links.gizmos.must_be_kind_of Array
|
30
|
-
links['gizmos'].must_be_kind_of Array
|
29
|
+
_(links.gizmos).must_be_kind_of Array
|
30
|
+
_(links['gizmos']).must_be_kind_of Array
|
31
31
|
end
|
32
32
|
|
33
33
|
describe 'plain link' do
|
34
34
|
let(:plain_link) { links.self }
|
35
35
|
it 'must be correct' do
|
36
|
-
plain_link._url.must_equal '/productions/1'
|
36
|
+
_(plain_link._url).must_equal '/productions/1'
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe 'templated link' do
|
41
|
-
let(:templated_link) { links.
|
41
|
+
let(:templated_link) { links.search }
|
42
42
|
it 'must expand' do
|
43
|
-
templated_link._expand(
|
43
|
+
_(templated_link._expand(search: 'gizmos')._url).must_equal '/productions/1?categories=gizmos'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -48,10 +48,10 @@ module Hyperclient
|
|
48
48
|
let(:curied_link) { links['image:thumbnail'] }
|
49
49
|
let(:curie) { links._curies['image'] }
|
50
50
|
it 'must expand' do
|
51
|
-
curied_link._expand(version: 'small')._url.must_equal '/images/thumbnails/small.jpg'
|
51
|
+
_(curied_link._expand(version: 'small')._url).must_equal '/images/thumbnails/small.jpg'
|
52
52
|
end
|
53
53
|
it 'exposes curie' do
|
54
|
-
curie.expand('thumbnail').must_equal '/docs/images/thumbnail'
|
54
|
+
_(curie.expand('thumbnail')).must_equal '/docs/images/thumbnail'
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,12 +59,12 @@ module Hyperclient
|
|
59
59
|
let(:gizmos) { links.gizmos }
|
60
60
|
|
61
61
|
it 'should have 2 items' do
|
62
|
-
gizmos.length.must_equal 2
|
62
|
+
_(gizmos.length).must_equal 2
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'must be an array of Links' do
|
66
66
|
gizmos.each do |link|
|
67
|
-
link.must_be_kind_of Link
|
67
|
+
_(link).must_be_kind_of Link
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -72,7 +72,7 @@ module Hyperclient
|
|
72
72
|
describe 'null link value' do
|
73
73
|
let(:null_link) { links.null_link }
|
74
74
|
it 'must be nil' do
|
75
|
-
null_link.must_be_nil
|
75
|
+
_(null_link).must_be_nil
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -7,16 +7,16 @@ module Hyperclient
|
|
7
7
|
EntryPoint.new('http://api.example.org/')
|
8
8
|
end
|
9
9
|
|
10
|
-
%w
|
10
|
+
%w[type deprecation name profile title hreflang].each do |prop|
|
11
11
|
describe prop do
|
12
12
|
it 'returns the property value' do
|
13
13
|
link = Link.new('key', { prop => 'value' }, entry_point)
|
14
|
-
link.send("_#{prop}").must_equal 'value'
|
14
|
+
_(link.send("_#{prop}")).must_equal 'value'
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'returns nil if the property is not present' do
|
18
18
|
link = Link.new('key', {}, entry_point)
|
19
|
-
link.send("_#{prop}").
|
19
|
+
_(link.send("_#{prop}")).must_be_nil
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -25,13 +25,13 @@ module Hyperclient
|
|
25
25
|
it 'returns true if the link is templated' do
|
26
26
|
link = Link.new('key', { 'templated' => true }, entry_point)
|
27
27
|
|
28
|
-
link._templated
|
28
|
+
_(link._templated?).must_equal true
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'returns false if the link is not templated' do
|
32
32
|
link = Link.new('key', {}, entry_point)
|
33
33
|
|
34
|
-
link._templated
|
34
|
+
_(link._templated?).must_equal false
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -39,13 +39,13 @@ module Hyperclient
|
|
39
39
|
it 'returns a list of required variables' do
|
40
40
|
link = Link.new('key', { 'href' => '/orders{?id,owner}', 'templated' => true }, entry_point)
|
41
41
|
|
42
|
-
link._variables.must_equal %w
|
42
|
+
_(link._variables).must_equal %w[id owner]
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'returns an empty array for untemplated links' do
|
46
46
|
link = Link.new('key', { 'href' => '/orders' }, entry_point)
|
47
47
|
|
48
|
-
link._variables.must_equal []
|
48
|
+
_(link._variables).must_equal []
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -53,41 +53,41 @@ module Hyperclient
|
|
53
53
|
describe 'required argument' do
|
54
54
|
it 'builds a Link with the templated URI representation' do
|
55
55
|
link = Link.new('key', { 'href' => '/orders/{id}', 'templated' => true }, entry_point)
|
56
|
-
link._expand(id: '1')._url.must_equal '/orders/1'
|
56
|
+
_(link._expand(id: '1')._url).must_equal '/orders/1'
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'expands an uri template without variables' do
|
60
60
|
link = Link.new('key', { 'href' => '/orders/{id}', 'templated' => true }, entry_point)
|
61
|
-
link._expand._url.must_equal '/orders/'
|
62
|
-
link._url.must_equal '/orders/'
|
61
|
+
_(link._expand._url).must_equal '/orders/'
|
62
|
+
_(link._url).must_equal '/orders/'
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
describe 'query string argument' do
|
67
67
|
it 'builds a Link with the templated URI representation' do
|
68
68
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
|
69
|
-
link._expand(id: '1')._url.must_equal '/orders?id=1'
|
69
|
+
_(link._expand(id: '1')._url).must_equal '/orders?id=1'
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'expands an uri template without variables' do
|
73
73
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
|
74
|
-
link._expand._url.must_equal '/orders'
|
75
|
-
link._url.must_equal '/orders'
|
74
|
+
_(link._expand._url).must_equal '/orders'
|
75
|
+
_(link._url).must_equal '/orders'
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'does not expand unknown variables' do
|
79
79
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
|
80
|
-
link._expand(unknown: '1')._url.must_equal '/orders'
|
80
|
+
_(link._expand(unknown: '1')._url).must_equal '/orders'
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'only expands known variables' do
|
84
84
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
|
85
|
-
link._expand(unknown: '1', id: '2')._url.must_equal '/orders?id=2'
|
85
|
+
_(link._expand(unknown: '1', id: '2')._url).must_equal '/orders?id=2'
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'only expands templated links' do
|
89
89
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => false }, entry_point)
|
90
|
-
link._expand(id: '1')._url.must_equal '/orders{?id}'
|
90
|
+
_(link._expand(id: '1')._url).must_equal '/orders{?id}'
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
@@ -96,36 +96,36 @@ module Hyperclient
|
|
96
96
|
it 'expands an uri template without variables' do
|
97
97
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
|
98
98
|
|
99
|
-
link._url.must_equal '/orders'
|
99
|
+
_(link._url).must_equal '/orders'
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'expands an uri template with variables' do
|
103
103
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, id: 1)
|
104
104
|
|
105
|
-
link._url.must_equal '/orders?id=1'
|
105
|
+
_(link._url).must_equal '/orders?id=1'
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'does not expand an uri template with unknown variables' do
|
109
109
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, unknown: 1)
|
110
110
|
|
111
|
-
link._url.must_equal '/orders'
|
111
|
+
_(link._url).must_equal '/orders'
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'only expands known variables in a uri template' do
|
115
115
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, unknown: 1, id: 2)
|
116
116
|
|
117
|
-
link._url.must_equal '/orders?id=2'
|
117
|
+
_(link._url).must_equal '/orders?id=2'
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'returns the link when no uri template' do
|
121
121
|
link = Link.new('key', { 'href' => '/orders' }, entry_point)
|
122
|
-
link._url.must_equal '/orders'
|
122
|
+
_(link._url).must_equal '/orders'
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'aliases to_s to _url' do
|
126
126
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, id: 1)
|
127
127
|
|
128
|
-
link.to_s.must_equal '/orders?id=1'
|
128
|
+
_(link.to_s).must_equal '/orders?id=1'
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -151,7 +151,7 @@ module Hyperclient
|
|
151
151
|
stub.get('http://api.example.org/productions/1') { [200, {}, nil] }
|
152
152
|
end
|
153
153
|
|
154
|
-
link._get.must_be_kind_of Resource
|
154
|
+
_(link._get).must_be_kind_of Resource
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'raises exceptions by default' do
|
@@ -161,35 +161,7 @@ module Hyperclient
|
|
161
161
|
stub.get('http://api.example.org/productions/1') { [400, {}, nil] }
|
162
162
|
end
|
163
163
|
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'executes requests asynchronously using futuroscope' do
|
168
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
169
|
-
|
170
|
-
stub_request(entry_point.connection) do |stub|
|
171
|
-
stub.get('http://api.example.org/productions/1') { [200, {}, nil] }
|
172
|
-
end
|
173
|
-
|
174
|
-
Futuroscope::Future.expects(:new).returns(stub(body: nil))
|
175
|
-
|
176
|
-
link._get
|
177
|
-
end
|
178
|
-
|
179
|
-
describe 'when entry_point.options is set to { async: false }' do
|
180
|
-
it 'executes requests synchronously without futuroscope' do
|
181
|
-
entry_point.options = { async: false }
|
182
|
-
|
183
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
184
|
-
|
185
|
-
stub_request(entry_point.connection) do |stub|
|
186
|
-
stub.get('http://api.example.org/productions/1') { [200, {}, nil] }
|
187
|
-
end
|
188
|
-
|
189
|
-
Futuroscope::Future.expects(:new).never
|
190
|
-
|
191
|
-
link._get
|
192
|
-
end
|
164
|
+
_(-> { link._get }).must_raise Faraday::ClientError
|
193
165
|
end
|
194
166
|
end
|
195
167
|
|
@@ -201,35 +173,7 @@ module Hyperclient
|
|
201
173
|
stub.options('http://api.example.org/productions/1') { [200, {}, nil] }
|
202
174
|
end
|
203
175
|
|
204
|
-
link._options.must_be_kind_of Resource
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'executes requests asynchronously using futuroscope' do
|
208
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
209
|
-
|
210
|
-
stub_request(entry_point.connection) do |stub|
|
211
|
-
stub.options('http://api.example.org/productions/1') { [200, {}, nil] }
|
212
|
-
end
|
213
|
-
|
214
|
-
Futuroscope::Future.expects(:new).returns(stub(body: nil))
|
215
|
-
|
216
|
-
link._options
|
217
|
-
end
|
218
|
-
|
219
|
-
describe 'when entry_point.options is set to { async: false }' do
|
220
|
-
it 'executes requests synchronously without futuroscope' do
|
221
|
-
entry_point.options = { async: false }
|
222
|
-
|
223
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
224
|
-
|
225
|
-
stub_request(entry_point.connection) do |stub|
|
226
|
-
stub.options('http://api.example.org/productions/1') { [200, {}, nil] }
|
227
|
-
end
|
228
|
-
|
229
|
-
Futuroscope::Future.expects(:new).never
|
230
|
-
|
231
|
-
link._options
|
232
|
-
end
|
176
|
+
_(link._options).must_be_kind_of Resource
|
233
177
|
end
|
234
178
|
end
|
235
179
|
|
@@ -241,35 +185,7 @@ module Hyperclient
|
|
241
185
|
stub.head('http://api.example.org/productions/1') { [200, {}, nil] }
|
242
186
|
end
|
243
187
|
|
244
|
-
link._head.must_be_kind_of Resource
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'executes requests asynchronously using futuroscope' do
|
248
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
249
|
-
|
250
|
-
stub_request(entry_point.connection) do |stub|
|
251
|
-
stub.head('http://api.example.org/productions/1') { [200, {}, nil] }
|
252
|
-
end
|
253
|
-
|
254
|
-
Futuroscope::Future.expects(:new).returns(stub(body: nil))
|
255
|
-
|
256
|
-
link._head
|
257
|
-
end
|
258
|
-
|
259
|
-
describe 'when entry_point.options is set to { async: false }' do
|
260
|
-
it 'executes requests synchronously without futuroscope' do
|
261
|
-
entry_point.options = { async: false }
|
262
|
-
|
263
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
264
|
-
|
265
|
-
stub_request(entry_point.connection) do |stub|
|
266
|
-
stub.head('http://api.example.org/productions/1') { [200, {}, nil] }
|
267
|
-
end
|
268
|
-
|
269
|
-
Futuroscope::Future.expects(:new).never
|
270
|
-
|
271
|
-
link._head
|
272
|
-
end
|
188
|
+
_(link._head).must_be_kind_of Resource
|
273
189
|
end
|
274
190
|
end
|
275
191
|
|
@@ -281,35 +197,7 @@ module Hyperclient
|
|
281
197
|
stub.delete('http://api.example.org/productions/1') { [200, {}, nil] }
|
282
198
|
end
|
283
199
|
|
284
|
-
link._delete.must_be_kind_of Resource
|
285
|
-
end
|
286
|
-
|
287
|
-
it 'executes requests asynchronously using futuroscope' do
|
288
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
289
|
-
|
290
|
-
stub_request(entry_point.connection) do |stub|
|
291
|
-
stub.delete('http://api.example.org/productions/1') { [200, {}, nil] }
|
292
|
-
end
|
293
|
-
|
294
|
-
Futuroscope::Future.expects(:new).returns(stub(body: nil))
|
295
|
-
|
296
|
-
link._delete
|
297
|
-
end
|
298
|
-
|
299
|
-
describe 'when entry_point.options is set to { async: false }' do
|
300
|
-
it 'executes requests synchronously without futuroscope' do
|
301
|
-
entry_point.options = { async: false }
|
302
|
-
|
303
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
304
|
-
|
305
|
-
stub_request(entry_point.connection) do |stub|
|
306
|
-
stub.delete('http://api.example.org/productions/1') { [200, {}, nil] }
|
307
|
-
end
|
308
|
-
|
309
|
-
Futuroscope::Future.expects(:new).never
|
310
|
-
|
311
|
-
link._delete
|
312
|
-
end
|
200
|
+
_(link._delete).must_be_kind_of Resource
|
313
201
|
end
|
314
202
|
end
|
315
203
|
|
@@ -321,7 +209,7 @@ module Hyperclient
|
|
321
209
|
stub.post('http://api.example.org/productions/1') { [200, {}, nil] }
|
322
210
|
end
|
323
211
|
|
324
|
-
link._post('foo' => 'bar').must_be_kind_of Resource
|
212
|
+
_(link._post('foo' => 'bar')).must_be_kind_of Resource
|
325
213
|
end
|
326
214
|
|
327
215
|
it 'defaults params to an empty hash' do
|
@@ -329,35 +217,7 @@ module Hyperclient
|
|
329
217
|
stub.post('http://api.example.org/productions/1') { [200, {}, nil] }
|
330
218
|
end
|
331
219
|
|
332
|
-
link._post.must_be_kind_of Resource
|
333
|
-
end
|
334
|
-
|
335
|
-
it 'executes requests asynchronously using futuroscope' do
|
336
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
337
|
-
|
338
|
-
stub_request(entry_point.connection) do |stub|
|
339
|
-
stub.post('http://api.example.org/productions/1') { [200, {}, nil] }
|
340
|
-
end
|
341
|
-
|
342
|
-
Futuroscope::Future.expects(:new).returns(stub(body: nil))
|
343
|
-
|
344
|
-
link._post
|
345
|
-
end
|
346
|
-
|
347
|
-
describe 'when entry_point.options is set to { async: false }' do
|
348
|
-
it 'executes requests synchronously without futuroscope' do
|
349
|
-
entry_point.options = { async: false }
|
350
|
-
|
351
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
352
|
-
|
353
|
-
stub_request(entry_point.connection) do |stub|
|
354
|
-
stub.post('http://api.example.org/productions/1') { [200, {}, nil] }
|
355
|
-
end
|
356
|
-
|
357
|
-
Futuroscope::Future.expects(:new).never
|
358
|
-
|
359
|
-
link._post
|
360
|
-
end
|
220
|
+
_(link._post).must_be_kind_of Resource
|
361
221
|
end
|
362
222
|
end
|
363
223
|
|
@@ -369,7 +229,7 @@ module Hyperclient
|
|
369
229
|
stub.put('http://api.example.org/productions/1', '{"foo":"bar"}') { [200, {}, nil] }
|
370
230
|
end
|
371
231
|
|
372
|
-
link._put('foo' => 'bar').must_be_kind_of Resource
|
232
|
+
_(link._put('foo' => 'bar')).must_be_kind_of Resource
|
373
233
|
end
|
374
234
|
|
375
235
|
it 'defaults params to an empty hash' do
|
@@ -377,35 +237,7 @@ module Hyperclient
|
|
377
237
|
stub.put('http://api.example.org/productions/1') { [200, {}, nil] }
|
378
238
|
end
|
379
239
|
|
380
|
-
link._put.must_be_kind_of Resource
|
381
|
-
end
|
382
|
-
|
383
|
-
it 'executes requests asynchronously using futuroscope' do
|
384
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
385
|
-
|
386
|
-
stub_request(entry_point.connection) do |stub|
|
387
|
-
stub.put('http://api.example.org/productions/1') { [200, {}, nil] }
|
388
|
-
end
|
389
|
-
|
390
|
-
Futuroscope::Future.expects(:new).returns(stub(body: nil))
|
391
|
-
|
392
|
-
link._put
|
393
|
-
end
|
394
|
-
|
395
|
-
describe 'when entry_point.options is set to { async: false }' do
|
396
|
-
it 'executes requests synchronously without futuroscope' do
|
397
|
-
entry_point.options = { async: false }
|
398
|
-
|
399
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
400
|
-
|
401
|
-
stub_request(entry_point.connection) do |stub|
|
402
|
-
stub.put('http://api.example.org/productions/1') { [200, {}, nil] }
|
403
|
-
end
|
404
|
-
|
405
|
-
Futuroscope::Future.expects(:new).never
|
406
|
-
|
407
|
-
link._put
|
408
|
-
end
|
240
|
+
_(link._put).must_be_kind_of Resource
|
409
241
|
end
|
410
242
|
end
|
411
243
|
|
@@ -417,7 +249,7 @@ module Hyperclient
|
|
417
249
|
stub.patch('http://api.example.org/productions/1', '{"foo":"bar"}') { [200, {}, nil] }
|
418
250
|
end
|
419
251
|
|
420
|
-
link._patch('foo' => 'bar').must_be_kind_of Resource
|
252
|
+
_(link._patch('foo' => 'bar')).must_be_kind_of Resource
|
421
253
|
end
|
422
254
|
|
423
255
|
it 'defaults params to an empty hash' do
|
@@ -425,35 +257,7 @@ module Hyperclient
|
|
425
257
|
stub.patch('http://api.example.org/productions/1') { [200, {}, nil] }
|
426
258
|
end
|
427
259
|
|
428
|
-
link._patch.must_be_kind_of Resource
|
429
|
-
end
|
430
|
-
|
431
|
-
it 'executes requests asynchronously using futuroscope' do
|
432
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
433
|
-
|
434
|
-
stub_request(entry_point.connection) do |stub|
|
435
|
-
stub.patch('http://api.example.org/productions/1') { [200, {}, nil] }
|
436
|
-
end
|
437
|
-
|
438
|
-
Futuroscope::Future.expects(:new).returns(stub(body: nil))
|
439
|
-
|
440
|
-
link._patch
|
441
|
-
end
|
442
|
-
|
443
|
-
describe 'when entry_point.options is set to { async: false }' do
|
444
|
-
it 'executes requests synchronously without futuroscope' do
|
445
|
-
entry_point.options = { async: false }
|
446
|
-
|
447
|
-
link = Link.new('key', { 'href' => '/productions/1' }, entry_point)
|
448
|
-
|
449
|
-
stub_request(entry_point.connection) do |stub|
|
450
|
-
stub.patch('http://api.example.org/productions/1') { [200, {}, nil] }
|
451
|
-
end
|
452
|
-
|
453
|
-
Futuroscope::Future.expects(:new).never
|
454
|
-
|
455
|
-
link._patch
|
456
|
-
end
|
260
|
+
_(link._patch).must_be_kind_of Resource
|
457
261
|
end
|
458
262
|
end
|
459
263
|
|
@@ -461,8 +265,8 @@ module Hyperclient
|
|
461
265
|
it 'outputs a custom-friendly output' do
|
462
266
|
link = Link.new('key', { 'href' => '/productions/1' }, 'foo')
|
463
267
|
|
464
|
-
link.inspect.must_include 'Link'
|
465
|
-
link.inspect.must_include '"href"=>"/productions/1"'
|
268
|
+
_(link.inspect).must_include 'Link'
|
269
|
+
_(link.inspect).must_include '"href"=>"/productions/1"'
|
466
270
|
end
|
467
271
|
end
|
468
272
|
|
@@ -475,8 +279,18 @@ module Hyperclient
|
|
475
279
|
stub.get('http://api.example.org/orders') { [200, {}, { '_embedded' => { 'orders' => [{ 'id' => 1 }] } }] }
|
476
280
|
end
|
477
281
|
|
478
|
-
resource.orders._embedded.orders.first.id.must_equal 1
|
479
|
-
resource.orders.first.id.must_equal 1
|
282
|
+
_(resource.orders._embedded.orders.first.id).must_equal 1
|
283
|
+
_(resource.orders.first.id).must_equal 1
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'can handle false values in the response' do
|
287
|
+
resource = Resource.new({ '_links' => { 'orders' => { 'href' => '/orders' } } }, entry_point)
|
288
|
+
|
289
|
+
stub_request(entry_point.connection) do |stub|
|
290
|
+
stub.get('http://api.example.org/orders') { [200, {}, { 'any' => false }] }
|
291
|
+
end
|
292
|
+
|
293
|
+
_(resource.orders.any).must_equal false
|
480
294
|
end
|
481
295
|
|
482
296
|
it "doesn't delegate when link key doesn't match" do
|
@@ -486,8 +300,8 @@ module Hyperclient
|
|
486
300
|
stub.get('http://api.example.org/orders') { [200, {}, { '_embedded' => { 'orders' => [{ 'id' => 1 }] } }] }
|
487
301
|
end
|
488
302
|
|
489
|
-
resource.foos._embedded.orders.first.id.must_equal 1
|
490
|
-
resource.foos.first.
|
303
|
+
_(resource.foos._embedded.orders.first.id).must_equal 1
|
304
|
+
_(resource.foos.first).must_be_nil
|
491
305
|
end
|
492
306
|
|
493
307
|
it 'backtracks when navigating links' do
|
@@ -497,7 +311,7 @@ module Hyperclient
|
|
497
311
|
stub.get('http://api.example.org/page2') { [200, {}, { '_links' => { 'next' => { 'href' => 'http://api.example.org/page3' } } }] }
|
498
312
|
end
|
499
313
|
|
500
|
-
resource.next._links.next._url.must_equal 'http://api.example.org/page3'
|
314
|
+
_(resource.next._links.next._url).must_equal 'http://api.example.org/page3'
|
501
315
|
end
|
502
316
|
end
|
503
317
|
|
@@ -521,18 +335,18 @@ module Hyperclient
|
|
521
335
|
end
|
522
336
|
|
523
337
|
it 'raises an error when the method does not exist in the resource' do
|
524
|
-
|
338
|
+
_(-> { link.this_method_does_not_exist }).must_raise NoMethodError
|
525
339
|
end
|
526
340
|
|
527
341
|
it 'responds to missing methods' do
|
528
342
|
resource.expects(:respond_to?).with('orders').returns(false)
|
529
343
|
resource.expects(:respond_to?).with('embedded').returns(true)
|
530
|
-
link.respond_to?(:embedded).must_equal true
|
344
|
+
_(link.respond_to?(:embedded)).must_equal true
|
531
345
|
end
|
532
346
|
|
533
347
|
it 'does not delegate to_ary to resource' do
|
534
348
|
resource.expects(:to_ary).never
|
535
|
-
[[link, link]].flatten.must_equal [link, link]
|
349
|
+
_([[link, link]].flatten).must_equal [link, link]
|
536
350
|
end
|
537
351
|
end
|
538
352
|
end
|