rom-http 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +81 -28
- data/README.md +15 -181
- data/lib/rom/http/associations/many_to_many.rb +12 -0
- data/lib/rom/http/associations/many_to_one.rb +20 -0
- data/lib/rom/http/associations/one_to_many.rb +20 -0
- data/lib/rom/http/associations/one_to_one.rb +12 -0
- data/lib/rom/http/associations.rb +14 -0
- data/lib/rom/http/attribute.rb +10 -0
- data/lib/rom/http/commands/create.rb +2 -0
- data/lib/rom/http/commands/delete.rb +2 -0
- data/lib/rom/http/commands/update.rb +2 -0
- data/lib/rom/http/commands.rb +6 -4
- data/lib/rom/http/dataset.rb +212 -115
- data/lib/rom/http/error.rb +2 -0
- data/lib/rom/http/gateway.rb +47 -6
- data/lib/rom/http/handlers/json.rb +64 -0
- data/lib/rom/http/handlers.rb +16 -0
- data/lib/rom/http/mapper_compiler.rb +11 -0
- data/lib/rom/http/relation.rb +22 -66
- data/lib/rom/http/schema/dsl.rb +12 -0
- data/lib/rom/http/schema.rb +40 -0
- data/lib/rom/http/transformer.rb +2 -0
- data/lib/rom/http/types.rb +13 -0
- data/lib/rom/http/version.rb +3 -1
- data/lib/rom/http.rb +9 -6
- data/lib/rom-http.rb +3 -1
- metadata +41 -120
- data/.gitignore +0 -16
- data/.rspec +0 -3
- data/.rubocop.yml +0 -22
- data/.rubocop_todo.yml +0 -12
- data/.travis.yml +0 -20
- data/Gemfile +0 -24
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -24
- data/examples/repository_with_combine.rb +0 -154
- data/lib/rom/http/dataset/class_interface.rb +0 -33
- data/rakelib/rubocop.rake +0 -18
- data/rom-http.gemspec +0 -32
- data/spec/integration/abstract/commands/create_spec.rb +0 -119
- data/spec/integration/abstract/commands/delete_spec.rb +0 -52
- data/spec/integration/abstract/commands/update_spec.rb +0 -119
- data/spec/integration/abstract/relation_spec.rb +0 -78
- data/spec/shared/setup.rb +0 -18
- data/spec/shared/users_and_tasks.rb +0 -30
- data/spec/spec_helper.rb +0 -19
- data/spec/support/mutant.rb +0 -10
- data/spec/unit/rom/http/dataset_spec.rb +0 -824
- data/spec/unit/rom/http/gateway_spec.rb +0 -69
- data/spec/unit/rom/http/relation_spec.rb +0 -268
@@ -1,824 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::HTTP::Dataset do
|
2
|
-
let(:klass) { ROM::HTTP::Dataset }
|
3
|
-
let(:dataset) { klass.new(config, options) }
|
4
|
-
let(:config) do
|
5
|
-
{
|
6
|
-
uri: uri,
|
7
|
-
request_handler: request_handler,
|
8
|
-
response_handler: response_handler
|
9
|
-
}
|
10
|
-
end
|
11
|
-
let(:options) { {} }
|
12
|
-
let(:uri) { 'http://localhost:3000' }
|
13
|
-
let(:request_handler) { double(Proc) }
|
14
|
-
let(:response_handler) { double(Proc) }
|
15
|
-
|
16
|
-
it { expect(klass).to be_kind_of(::Dry::Configurable) }
|
17
|
-
it { expect(dataset).to be_kind_of(::Enumerable) }
|
18
|
-
|
19
|
-
describe 'settings' do
|
20
|
-
describe 'default_request_handler' do
|
21
|
-
it 'defaults to nil' do
|
22
|
-
expect(klass.config.default_request_handler).to be nil
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'default_response_handler' do
|
27
|
-
it 'defaults to nil' do
|
28
|
-
expect(klass.config.default_response_handler).to be nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe 'defaults' do
|
34
|
-
describe '#config' do
|
35
|
-
subject { dataset.config }
|
36
|
-
|
37
|
-
it { is_expected.to eq(config) }
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'options' do
|
41
|
-
subject { dataset }
|
42
|
-
|
43
|
-
context 'with options passed' do
|
44
|
-
let(:options) do
|
45
|
-
{
|
46
|
-
request_method: :put,
|
47
|
-
headers: {
|
48
|
-
'Accept' => 'application/json'
|
49
|
-
}
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
its(:base_path) { is_expected.to eq('') }
|
54
|
-
its(:request_method) { is_expected.to eq(:put) }
|
55
|
-
its(:path) { is_expected.to eq('') }
|
56
|
-
its(:params) { is_expected.to eq({}) }
|
57
|
-
its(:headers) { is_expected.to eq('Accept' => 'application/json') }
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'with no options passed' do
|
61
|
-
its(:base_path) { is_expected.to eq('') }
|
62
|
-
its(:request_method) { is_expected.to eq(:get) }
|
63
|
-
its(:path) { is_expected.to eq('') }
|
64
|
-
its(:params) { is_expected.to eq({}) }
|
65
|
-
its(:headers) { is_expected.to eq({}) }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe '.default_request_handler' do
|
71
|
-
before do
|
72
|
-
module Test
|
73
|
-
class Dataset < ROM::HTTP::Dataset; end
|
74
|
-
end
|
75
|
-
|
76
|
-
allow(Dry::Core::Deprecations).to receive(:announce)
|
77
|
-
end
|
78
|
-
|
79
|
-
after { Test::Dataset.reset_config }
|
80
|
-
|
81
|
-
context 'when no default_request_handler set' do
|
82
|
-
subject! { Test::Dataset.default_request_handler }
|
83
|
-
|
84
|
-
it 'returns nil' do
|
85
|
-
expect(Dry::Core::Deprecations).to have_received(:announce).with(
|
86
|
-
:default_request_handler,
|
87
|
-
'use configuration instead'
|
88
|
-
)
|
89
|
-
is_expected.to be nil
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'when default_request_handler set' do
|
94
|
-
before do
|
95
|
-
Test::Dataset.default_request_handler(request_handler)
|
96
|
-
end
|
97
|
-
|
98
|
-
subject! { Test::Dataset.default_request_handler }
|
99
|
-
|
100
|
-
it 'returns the default request handler' do
|
101
|
-
expect(Dry::Core::Deprecations).to have_received(:announce).with(
|
102
|
-
:default_request_handler,
|
103
|
-
'use configuration instead'
|
104
|
-
).twice
|
105
|
-
is_expected.to eq request_handler
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe '.default_response_handler' do
|
111
|
-
before do
|
112
|
-
module Test
|
113
|
-
class Dataset < ROM::HTTP::Dataset; end
|
114
|
-
end
|
115
|
-
|
116
|
-
allow(Dry::Core::Deprecations).to receive(:announce)
|
117
|
-
end
|
118
|
-
|
119
|
-
after { Test::Dataset.reset_config }
|
120
|
-
|
121
|
-
context 'when no default_response_handler set' do
|
122
|
-
subject! { Test::Dataset.default_response_handler }
|
123
|
-
|
124
|
-
it 'returns nil' do
|
125
|
-
expect(Dry::Core::Deprecations).to have_received(:announce).with(
|
126
|
-
:default_response_handler,
|
127
|
-
'use configuration instead'
|
128
|
-
)
|
129
|
-
is_expected.to be nil
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context 'when default_response_handler set' do
|
134
|
-
before do
|
135
|
-
Test::Dataset.default_response_handler(response_handler)
|
136
|
-
end
|
137
|
-
|
138
|
-
subject! { Test::Dataset.default_response_handler }
|
139
|
-
|
140
|
-
it 'returns the default response handler' do
|
141
|
-
expect(Dry::Core::Deprecations).to have_received(:announce).with(
|
142
|
-
:default_response_handler,
|
143
|
-
'use configuration instead'
|
144
|
-
).twice
|
145
|
-
is_expected.to eq response_handler
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe '#uri' do
|
151
|
-
context 'when no uri configured' do
|
152
|
-
let(:config) { {} }
|
153
|
-
|
154
|
-
it do
|
155
|
-
expect { dataset.uri }.to raise_error(ROM::HTTP::Error)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context 'when uri configured' do
|
160
|
-
subject! { dataset.uri }
|
161
|
-
|
162
|
-
context 'when request method is GET' do
|
163
|
-
context 'with params' do
|
164
|
-
let(:options) do
|
165
|
-
{
|
166
|
-
params: {
|
167
|
-
username: 'John',
|
168
|
-
role: 'admin'
|
169
|
-
}
|
170
|
-
}
|
171
|
-
end
|
172
|
-
let(:expected_uri) { URI("#{uri}?username=John&role=admin") }
|
173
|
-
|
174
|
-
it { is_expected.to eq(expected_uri) }
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
context 'when request method is not GET' do
|
179
|
-
context 'with params' do
|
180
|
-
let(:options) do
|
181
|
-
{
|
182
|
-
request_method: :post,
|
183
|
-
params: {
|
184
|
-
username: 'John',
|
185
|
-
role: 'admin'
|
186
|
-
}
|
187
|
-
}
|
188
|
-
end
|
189
|
-
let(:expected_uri) { URI(uri) }
|
190
|
-
|
191
|
-
it { is_expected.to eq(expected_uri) }
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
context 'without dataset name' do
|
196
|
-
context 'with no path' do
|
197
|
-
let(:expected_uri) { URI(uri) }
|
198
|
-
|
199
|
-
it { is_expected.to eq(expected_uri) }
|
200
|
-
end
|
201
|
-
|
202
|
-
context 'with path' do
|
203
|
-
context 'without custom base_path' do
|
204
|
-
let(:options) { { path: '/users' } }
|
205
|
-
let(:expected_uri) { URI("#{uri}/users") }
|
206
|
-
|
207
|
-
it { is_expected.to eq(expected_uri) }
|
208
|
-
end
|
209
|
-
|
210
|
-
context 'with custom base_path' do
|
211
|
-
let(:options) { { base_path: '/blog', path: '/users' } }
|
212
|
-
let(:expected_uri) { URI("#{uri}/blog/users") }
|
213
|
-
|
214
|
-
it { is_expected.to eq(expected_uri) }
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
context 'with dataset name' do
|
220
|
-
let(:config) { super().merge(name: :blog) }
|
221
|
-
|
222
|
-
context 'with no path' do
|
223
|
-
let(:expected_uri) { URI("#{uri}/blog") }
|
224
|
-
|
225
|
-
it { is_expected.to eq(expected_uri) }
|
226
|
-
end
|
227
|
-
|
228
|
-
context 'with path' do
|
229
|
-
context 'without custom base_path' do
|
230
|
-
let(:options) { { path: '/users' } }
|
231
|
-
let(:expected_uri) { URI("#{uri}/blog/users") }
|
232
|
-
|
233
|
-
it { is_expected.to eq(expected_uri) }
|
234
|
-
end
|
235
|
-
|
236
|
-
context 'with custom base_path' do
|
237
|
-
let(:options) { { base_path: '/bloggers', path: '/users' } }
|
238
|
-
let(:expected_uri) { URI("#{uri}/bloggers/users") }
|
239
|
-
|
240
|
-
it { is_expected.to eq(expected_uri) }
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
context 'with custom base_path' do
|
246
|
-
let(:config) { super().merge(name: :blog) }
|
247
|
-
|
248
|
-
context 'with no path' do
|
249
|
-
let(:expected_uri) { URI("#{uri}/blog") }
|
250
|
-
|
251
|
-
it { is_expected.to eq(expected_uri) }
|
252
|
-
end
|
253
|
-
|
254
|
-
context 'with path' do
|
255
|
-
let(:options) { { path: '/users' } }
|
256
|
-
let(:expected_uri) { URI("#{uri}/blog/users") }
|
257
|
-
|
258
|
-
it { is_expected.to eq(expected_uri) }
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe '#headers' do
|
265
|
-
subject { dataset.headers }
|
266
|
-
|
267
|
-
context 'with no headers configured' do
|
268
|
-
context 'with no headers option' do
|
269
|
-
it { is_expected.to eq({}) }
|
270
|
-
end
|
271
|
-
|
272
|
-
context 'with headers option' do
|
273
|
-
let(:headers) { { 'Accept' => 'application/json' } }
|
274
|
-
let(:options) { { headers: headers } }
|
275
|
-
|
276
|
-
it { is_expected.to eq(headers) }
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
context 'with headers configured' do
|
281
|
-
context 'with no headers option' do
|
282
|
-
let(:headers) { { 'Accept' => 'application/json' } }
|
283
|
-
let(:config) do
|
284
|
-
super().merge(headers: headers)
|
285
|
-
end
|
286
|
-
|
287
|
-
it { is_expected.to eq(headers) }
|
288
|
-
end
|
289
|
-
|
290
|
-
context 'with headers option' do
|
291
|
-
let(:config_headers) { { 'Content-Type' => 'application/json' } }
|
292
|
-
let(:config) do
|
293
|
-
super().merge(headers: config_headers)
|
294
|
-
end
|
295
|
-
let(:option_headers) { { 'Accept' => 'application/json' } }
|
296
|
-
let(:options) { { headers: option_headers } }
|
297
|
-
|
298
|
-
it do
|
299
|
-
is_expected.to eq(
|
300
|
-
'Content-Type' => 'application/json',
|
301
|
-
'Accept' => 'application/json'
|
302
|
-
)
|
303
|
-
end
|
304
|
-
end
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
describe '#name' do
|
309
|
-
subject { dataset.name }
|
310
|
-
|
311
|
-
context 'with no name configured' do
|
312
|
-
it { is_expected.to eq('') }
|
313
|
-
end
|
314
|
-
|
315
|
-
context 'with name configured' do
|
316
|
-
let(:name) { 'users' }
|
317
|
-
let(:config) do
|
318
|
-
super().merge(name: name)
|
319
|
-
end
|
320
|
-
|
321
|
-
it { is_expected.to eq(name) }
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
describe '#base_path' do
|
326
|
-
subject { dataset.base_path }
|
327
|
-
|
328
|
-
context 'with no base_path option' do
|
329
|
-
context 'when dataset name is set' do
|
330
|
-
let(:config) do
|
331
|
-
{
|
332
|
-
uri: uri,
|
333
|
-
request_handler: request_handler,
|
334
|
-
response_handler: response_handler,
|
335
|
-
name: :users
|
336
|
-
}
|
337
|
-
end
|
338
|
-
|
339
|
-
it 'returns the dataset name as a string' do
|
340
|
-
is_expected.to eq('users')
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
context 'when dataset name is not set' do
|
345
|
-
it 'returns an empty string' do
|
346
|
-
is_expected.to eq('')
|
347
|
-
end
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
context 'with base_path option' do
|
352
|
-
context 'when base_path is absolute' do
|
353
|
-
let(:base_path) { '/users' }
|
354
|
-
let(:options) { { base_path: base_path } }
|
355
|
-
|
356
|
-
it 'removes the leading /' do
|
357
|
-
is_expected.to eq('users')
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
context 'when base_path is not absolute' do
|
362
|
-
let(:base_path) { 'users' }
|
363
|
-
let(:options) { { base_path: base_path } }
|
364
|
-
|
365
|
-
it { is_expected.to eq(base_path) }
|
366
|
-
end
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
describe '#path' do
|
371
|
-
subject { dataset.path }
|
372
|
-
|
373
|
-
context 'with no path option' do
|
374
|
-
context 'without dataset name' do
|
375
|
-
it { is_expected.to eq('') }
|
376
|
-
end
|
377
|
-
|
378
|
-
context 'with dataset name' do
|
379
|
-
let(:config) { super().merge(name: :users) }
|
380
|
-
it { is_expected.to eq('users') }
|
381
|
-
end
|
382
|
-
|
383
|
-
context 'with base path' do
|
384
|
-
let(:options) { { base_path: '/users' } }
|
385
|
-
it { is_expected.to eq('users') }
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
context 'with path option' do
|
390
|
-
context 'when path is absolute' do
|
391
|
-
let(:path) { '/users' }
|
392
|
-
|
393
|
-
context 'without dataset name' do
|
394
|
-
let(:options) { { path: path } }
|
395
|
-
|
396
|
-
it 'removes the leading /' do
|
397
|
-
is_expected.to eq('users')
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
context 'with dataset name' do
|
402
|
-
let(:config) { super().merge(name: :blog) }
|
403
|
-
let(:options) { { path: path } }
|
404
|
-
|
405
|
-
it { is_expected.to eq('blog/users') }
|
406
|
-
end
|
407
|
-
|
408
|
-
context 'with base path' do
|
409
|
-
let(:options) { { base_path: '/blog', path: path } }
|
410
|
-
|
411
|
-
it { is_expected.to eq('blog/users') }
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
context 'when path is not absolute' do
|
416
|
-
let(:path) { 'users' }
|
417
|
-
|
418
|
-
context 'without dataset name' do
|
419
|
-
let(:options) { { path: path } }
|
420
|
-
|
421
|
-
it { is_expected.to eq(path) }
|
422
|
-
end
|
423
|
-
|
424
|
-
context 'with dataset name' do
|
425
|
-
let(:config) { super().merge(name: :blog) }
|
426
|
-
let(:options) { { path: path } }
|
427
|
-
|
428
|
-
it { is_expected.to eq('blog/users') }
|
429
|
-
end
|
430
|
-
|
431
|
-
context 'with base path' do
|
432
|
-
let(:options) { { base_path: '/blog', path: path } }
|
433
|
-
|
434
|
-
it { is_expected.to eq('blog/users') }
|
435
|
-
end
|
436
|
-
end
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
describe '#absolute_path' do
|
441
|
-
subject { dataset.absolute_path }
|
442
|
-
|
443
|
-
context 'with no path option' do
|
444
|
-
it { is_expected.to eq('/') }
|
445
|
-
end
|
446
|
-
|
447
|
-
context 'with path option' do
|
448
|
-
context 'when path is absolute' do
|
449
|
-
let(:path) { '/users' }
|
450
|
-
let(:options) { { path: path } }
|
451
|
-
|
452
|
-
it { is_expected.to eq(path) }
|
453
|
-
end
|
454
|
-
|
455
|
-
context 'when path is not absolute' do
|
456
|
-
let(:path) { 'users' }
|
457
|
-
let(:options) { { path: path } }
|
458
|
-
|
459
|
-
it { is_expected.to eq("/#{path}") }
|
460
|
-
end
|
461
|
-
end
|
462
|
-
end
|
463
|
-
|
464
|
-
describe '#request_method' do
|
465
|
-
subject { dataset.request_method }
|
466
|
-
|
467
|
-
context 'with no request_method option' do
|
468
|
-
it { is_expected.to eq(:get) }
|
469
|
-
end
|
470
|
-
|
471
|
-
context 'with request_method option' do
|
472
|
-
let(:request_method) { :put }
|
473
|
-
let(:options) { { request_method: request_method } }
|
474
|
-
|
475
|
-
it { is_expected.to eq(request_method) }
|
476
|
-
end
|
477
|
-
end
|
478
|
-
|
479
|
-
describe '#params' do
|
480
|
-
subject { dataset.params }
|
481
|
-
|
482
|
-
context 'with no params option' do
|
483
|
-
it { is_expected.to eq({}) }
|
484
|
-
end
|
485
|
-
|
486
|
-
context 'with params option' do
|
487
|
-
let(:params) { { name: 'Jack' } }
|
488
|
-
let(:options) { { params: params } }
|
489
|
-
|
490
|
-
it { is_expected.to eq(params) }
|
491
|
-
end
|
492
|
-
end
|
493
|
-
|
494
|
-
describe '#with_headers' do
|
495
|
-
let(:headers) { { 'Accept' => 'application/json' } }
|
496
|
-
let(:new_dataset) { dataset.with_headers(headers) }
|
497
|
-
|
498
|
-
subject! { new_dataset }
|
499
|
-
|
500
|
-
its(:config) { is_expected.to eq(config) }
|
501
|
-
its(:base_path) { is_expected.to eq('') }
|
502
|
-
its(:request_method) { is_expected.to eq(:get) }
|
503
|
-
its(:path) { is_expected.to eq('') }
|
504
|
-
its(:params) { is_expected.to eq({}) }
|
505
|
-
its(:headers) { is_expected.to eq(headers) }
|
506
|
-
|
507
|
-
it { is_expected.to_not be(dataset) }
|
508
|
-
it { is_expected.to be_a(ROM::HTTP::Dataset) }
|
509
|
-
end
|
510
|
-
|
511
|
-
describe '#add_header' do
|
512
|
-
let(:header_key) { 'Accept' }
|
513
|
-
let(:header_value) { 'application/json' }
|
514
|
-
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
515
|
-
|
516
|
-
before do
|
517
|
-
allow(dataset).to receive(:with_headers).and_return(new_dataset)
|
518
|
-
end
|
519
|
-
|
520
|
-
subject! { dataset.add_header(header_key, header_value) }
|
521
|
-
|
522
|
-
context 'with existing headers configured' do
|
523
|
-
let(:config_headers) { { 'Content-Type' => 'application/json', 'Accept' => 'text/html' } }
|
524
|
-
let(:config) { super().merge(headers: config_headers) }
|
525
|
-
|
526
|
-
it do
|
527
|
-
expect(dataset).to have_received(:with_headers).with(
|
528
|
-
'Content-Type' => 'application/json',
|
529
|
-
header_key => header_value
|
530
|
-
)
|
531
|
-
end
|
532
|
-
it { is_expected.to eq(new_dataset) }
|
533
|
-
end
|
534
|
-
|
535
|
-
context 'without existing headers configured' do
|
536
|
-
it do
|
537
|
-
expect(dataset).to have_received(:with_headers).with(
|
538
|
-
header_key => header_value
|
539
|
-
)
|
540
|
-
end
|
541
|
-
it { is_expected.to eq(new_dataset) }
|
542
|
-
end
|
543
|
-
end
|
544
|
-
|
545
|
-
describe '#with_options' do
|
546
|
-
let(:name) { 'Jill' }
|
547
|
-
let(:options) { { params: { name: name } } }
|
548
|
-
let(:new_dataset) { dataset.with_options(options) }
|
549
|
-
|
550
|
-
subject! { new_dataset }
|
551
|
-
|
552
|
-
its(:config) { is_expected.to eq(config) }
|
553
|
-
its(:base_path) { is_expected.to eq('') }
|
554
|
-
its(:request_method) { is_expected.to eq(:get) }
|
555
|
-
its(:path) { is_expected.to eq('') }
|
556
|
-
its(:params) { is_expected.to eq(name: name) }
|
557
|
-
its(:headers) { is_expected.to eq({}) }
|
558
|
-
|
559
|
-
it { is_expected.to_not be(dataset) }
|
560
|
-
it { is_expected.to be_a(ROM::HTTP::Dataset) }
|
561
|
-
end
|
562
|
-
|
563
|
-
describe '#with_base_path' do
|
564
|
-
let(:base_path) { '/users/tasks' }
|
565
|
-
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
566
|
-
|
567
|
-
before do
|
568
|
-
allow(dataset).to receive(:with_options).and_return(new_dataset)
|
569
|
-
end
|
570
|
-
|
571
|
-
subject! { dataset.with_base_path(base_path) }
|
572
|
-
|
573
|
-
it { expect(dataset).to have_received(:with_options).with(base_path: base_path) }
|
574
|
-
it { is_expected.to eq(new_dataset) }
|
575
|
-
end
|
576
|
-
|
577
|
-
describe '#with_path' do
|
578
|
-
let(:path) { '/users/tasks' }
|
579
|
-
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
580
|
-
|
581
|
-
before do
|
582
|
-
allow(dataset).to receive(:with_options).and_return(new_dataset)
|
583
|
-
end
|
584
|
-
|
585
|
-
subject! { dataset.with_path(path) }
|
586
|
-
|
587
|
-
it { expect(dataset).to have_received(:with_options).with(path: path) }
|
588
|
-
it { is_expected.to eq(new_dataset) }
|
589
|
-
end
|
590
|
-
|
591
|
-
describe '#append_path' do
|
592
|
-
let(:path) { 'tasks' }
|
593
|
-
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
594
|
-
|
595
|
-
before do
|
596
|
-
allow(dataset).to receive(:with_options).and_return(new_dataset)
|
597
|
-
end
|
598
|
-
|
599
|
-
subject! { dataset.append_path(path) }
|
600
|
-
|
601
|
-
context 'without existing path' do
|
602
|
-
it { expect(dataset).to have_received(:with_options).with(path: 'tasks') }
|
603
|
-
it { is_expected.to eq(new_dataset) }
|
604
|
-
end
|
605
|
-
|
606
|
-
context 'with existing path' do
|
607
|
-
let(:options) { { path: '/users' } }
|
608
|
-
|
609
|
-
it { expect(dataset).to have_received(:with_options).with(path: 'users/tasks') }
|
610
|
-
it { is_expected.to eq(new_dataset) }
|
611
|
-
end
|
612
|
-
end
|
613
|
-
|
614
|
-
describe '#with_request_method' do
|
615
|
-
let(:request_method) { :put }
|
616
|
-
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
617
|
-
|
618
|
-
before do
|
619
|
-
allow(dataset).to receive(:with_options).and_return(new_dataset)
|
620
|
-
end
|
621
|
-
|
622
|
-
subject! { dataset.with_request_method(request_method) }
|
623
|
-
|
624
|
-
it { expect(dataset).to have_received(:with_options).with(request_method: request_method) }
|
625
|
-
it { is_expected.to eq(new_dataset) }
|
626
|
-
end
|
627
|
-
|
628
|
-
describe '#with_params' do
|
629
|
-
let(:name) { 'Jack' }
|
630
|
-
let(:params) { { user: { name: name } } }
|
631
|
-
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
632
|
-
|
633
|
-
before do
|
634
|
-
allow(dataset).to receive(:with_options).and_return(new_dataset)
|
635
|
-
end
|
636
|
-
|
637
|
-
subject! { dataset.with_params(params) }
|
638
|
-
|
639
|
-
it { expect(dataset).to have_received(:with_options).with(params: params) }
|
640
|
-
it { is_expected.to eq(new_dataset) }
|
641
|
-
end
|
642
|
-
|
643
|
-
describe '#add_params' do
|
644
|
-
let(:options) do
|
645
|
-
{
|
646
|
-
params: {
|
647
|
-
user: {
|
648
|
-
uid: 3
|
649
|
-
}
|
650
|
-
}
|
651
|
-
}
|
652
|
-
end
|
653
|
-
let(:params) { { user: { name: 'Jack' } } }
|
654
|
-
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
655
|
-
|
656
|
-
before do
|
657
|
-
allow(dataset).to receive(:with_options).and_return(new_dataset)
|
658
|
-
end
|
659
|
-
|
660
|
-
subject! { dataset.add_params(params) }
|
661
|
-
|
662
|
-
it do
|
663
|
-
expect(dataset).to have_received(:with_options).with(params: {
|
664
|
-
user: {
|
665
|
-
uid: 3,
|
666
|
-
name: 'Jack'
|
667
|
-
}
|
668
|
-
})
|
669
|
-
end
|
670
|
-
it { is_expected.to eq(new_dataset) }
|
671
|
-
end
|
672
|
-
|
673
|
-
describe '#each' do
|
674
|
-
let(:response) { double(Array) }
|
675
|
-
let(:block) { proc {} }
|
676
|
-
let(:result) { double }
|
677
|
-
|
678
|
-
before do
|
679
|
-
allow(dataset).to receive(:response).and_return(response)
|
680
|
-
allow(response).to receive(:each).and_yield.and_return(result)
|
681
|
-
end
|
682
|
-
|
683
|
-
context 'with no block given' do
|
684
|
-
subject! { dataset.each }
|
685
|
-
|
686
|
-
it { expect(dataset).to_not have_received(:response) }
|
687
|
-
it { expect(response).to_not have_received(:each) }
|
688
|
-
it { is_expected.to be_kind_of(Enumerable) }
|
689
|
-
end
|
690
|
-
|
691
|
-
context 'with block given' do
|
692
|
-
subject! { dataset.each(&block) }
|
693
|
-
|
694
|
-
it { expect(dataset).to have_received(:response).once }
|
695
|
-
it { expect(response).to have_received(:each) }
|
696
|
-
it { is_expected.to eq(result) }
|
697
|
-
end
|
698
|
-
end
|
699
|
-
|
700
|
-
describe '#insert' do
|
701
|
-
let(:name) { 'Jill' }
|
702
|
-
let(:params) { { user: { name: name } } }
|
703
|
-
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
704
|
-
let(:response) { double }
|
705
|
-
|
706
|
-
before do
|
707
|
-
allow(dataset).to receive(:with_options).and_return(new_dataset)
|
708
|
-
allow(new_dataset).to receive(:response).and_return(response)
|
709
|
-
end
|
710
|
-
|
711
|
-
subject! { dataset.insert(params) }
|
712
|
-
|
713
|
-
it do
|
714
|
-
expect(dataset).to have_received(:with_options).with(
|
715
|
-
request_method: :post,
|
716
|
-
params: params
|
717
|
-
)
|
718
|
-
end
|
719
|
-
it { expect(new_dataset).to have_received(:response) }
|
720
|
-
it { is_expected.to eq(response) }
|
721
|
-
end
|
722
|
-
|
723
|
-
describe '#update' do
|
724
|
-
let(:name) { 'Jill' }
|
725
|
-
let(:params) { { user: { name: name } } }
|
726
|
-
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
727
|
-
let(:response) { double }
|
728
|
-
|
729
|
-
before do
|
730
|
-
allow(dataset).to receive(:with_options).and_return(new_dataset)
|
731
|
-
allow(new_dataset).to receive(:response).and_return(response)
|
732
|
-
end
|
733
|
-
|
734
|
-
subject! { dataset.update(params) }
|
735
|
-
|
736
|
-
it do
|
737
|
-
expect(dataset).to have_received(:with_options).with(
|
738
|
-
request_method: :put,
|
739
|
-
params: params
|
740
|
-
)
|
741
|
-
end
|
742
|
-
it { expect(new_dataset).to have_received(:response) }
|
743
|
-
it { is_expected.to eq(response) }
|
744
|
-
end
|
745
|
-
|
746
|
-
describe '#delete' do
|
747
|
-
let(:new_dataset) { double(ROM::HTTP::Dataset) }
|
748
|
-
let(:response) { double }
|
749
|
-
|
750
|
-
before do
|
751
|
-
allow(dataset).to receive(:with_options).and_return(new_dataset)
|
752
|
-
allow(new_dataset).to receive(:response).and_return(response)
|
753
|
-
end
|
754
|
-
|
755
|
-
subject! { dataset.delete }
|
756
|
-
|
757
|
-
it do
|
758
|
-
expect(dataset).to have_received(:with_options).with(
|
759
|
-
request_method: :delete
|
760
|
-
)
|
761
|
-
end
|
762
|
-
it { expect(new_dataset).to have_received(:response) }
|
763
|
-
it { is_expected.to eq(response) }
|
764
|
-
end
|
765
|
-
|
766
|
-
describe '#response' do
|
767
|
-
let(:response) { double }
|
768
|
-
let(:result) { double }
|
769
|
-
|
770
|
-
context 'when request_handler and response_handler configured' do
|
771
|
-
before do
|
772
|
-
allow(request_handler).to receive(:call).and_return(response)
|
773
|
-
allow(response_handler).to receive(:call).and_return(result)
|
774
|
-
end
|
775
|
-
|
776
|
-
subject! { dataset.response }
|
777
|
-
|
778
|
-
it { expect(request_handler).to have_received(:call).with(dataset) }
|
779
|
-
it { expect(response_handler).to have_received(:call).with(response, dataset) }
|
780
|
-
it { is_expected.to eq(result) }
|
781
|
-
end
|
782
|
-
|
783
|
-
context 'when request_handler and response_handler configured' do
|
784
|
-
let(:dataset) { Test::Dataset.new(config, options) }
|
785
|
-
let(:config) { {} }
|
786
|
-
|
787
|
-
before do
|
788
|
-
module Test
|
789
|
-
class Dataset < ROM::HTTP::Dataset; end
|
790
|
-
end
|
791
|
-
|
792
|
-
Test::Dataset.default_request_handler(request_handler)
|
793
|
-
Test::Dataset.default_response_handler(response_handler)
|
794
|
-
|
795
|
-
allow(request_handler).to receive(:call).and_return(response)
|
796
|
-
allow(response_handler).to receive(:call).and_return(result)
|
797
|
-
end
|
798
|
-
|
799
|
-
after { Test::Dataset.reset_config }
|
800
|
-
|
801
|
-
subject! { dataset.response }
|
802
|
-
|
803
|
-
it { expect(request_handler).to have_received(:call).with(dataset) }
|
804
|
-
it { expect(response_handler).to have_received(:call).with(response, dataset) }
|
805
|
-
it { is_expected.to eq(result) }
|
806
|
-
end
|
807
|
-
|
808
|
-
context 'when no request_handler configured and no default set' do
|
809
|
-
let(:config) { { response_handler: response_handler } }
|
810
|
-
|
811
|
-
it do
|
812
|
-
expect { dataset.response }.to raise_error(ROM::HTTP::Error)
|
813
|
-
end
|
814
|
-
end
|
815
|
-
|
816
|
-
context 'when no response_handler configured and no default set' do
|
817
|
-
let(:config) { { request_handler: request_handler } }
|
818
|
-
|
819
|
-
it do
|
820
|
-
expect { dataset.response }.to raise_error(ROM::HTTP::Error)
|
821
|
-
end
|
822
|
-
end
|
823
|
-
end
|
824
|
-
end
|