acfs 1.0.0.dev.1.b305 → 1.0.0
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 +5 -13
- data/CHANGELOG.md +64 -0
- data/README.md +2 -2
- data/acfs.gemspec +4 -4
- data/lib/acfs.rb +7 -5
- data/lib/acfs/adapter/base.rb +0 -2
- data/lib/acfs/adapter/typhoeus.rb +17 -13
- data/lib/acfs/collections/paginatable.rb +10 -10
- data/lib/acfs/configuration.rb +4 -5
- data/lib/acfs/errors.rb +10 -9
- data/lib/acfs/global.rb +16 -7
- data/lib/acfs/location.rb +11 -11
- data/lib/acfs/middleware/base.rb +1 -2
- data/lib/acfs/middleware/json.rb +27 -0
- data/lib/acfs/middleware/logger.rb +0 -2
- data/lib/acfs/middleware/msgpack.rb +30 -0
- data/lib/acfs/middleware/print.rb +0 -2
- data/lib/acfs/middleware/serializer.rb +39 -0
- data/lib/acfs/operation.rb +5 -5
- data/lib/acfs/request.rb +4 -4
- data/lib/acfs/request/callbacks.rb +2 -3
- data/lib/acfs/resource.rb +2 -2
- data/lib/acfs/resource/attributes.rb +10 -37
- data/lib/acfs/resource/attributes/base.rb +10 -19
- data/lib/acfs/resource/attributes/boolean.rb +10 -8
- data/lib/acfs/resource/attributes/date_time.rb +6 -9
- data/lib/acfs/resource/attributes/dict.rb +37 -0
- data/lib/acfs/resource/attributes/float.rb +11 -5
- data/lib/acfs/resource/attributes/integer.rb +7 -5
- data/lib/acfs/resource/attributes/list.rb +13 -6
- data/lib/acfs/resource/attributes/string.rb +3 -5
- data/lib/acfs/resource/attributes/uuid.rb +8 -17
- data/lib/acfs/resource/loadable.rb +0 -1
- data/lib/acfs/resource/locatable.rb +0 -4
- data/lib/acfs/resource/operational.rb +0 -2
- data/lib/acfs/resource/persistence.rb +17 -17
- data/lib/acfs/resource/query_methods.rb +3 -5
- data/lib/acfs/resource/service.rb +0 -2
- data/lib/acfs/resource/validation.rb +0 -2
- data/lib/acfs/response.rb +1 -2
- data/lib/acfs/response/formats.rb +1 -2
- data/lib/acfs/response/status.rb +3 -5
- data/lib/acfs/runner.rb +21 -11
- data/lib/acfs/service.rb +4 -6
- data/lib/acfs/service/middleware.rb +20 -30
- data/lib/acfs/service/middleware/stack.rb +63 -0
- data/lib/acfs/singleton_resource.rb +0 -2
- data/lib/acfs/stub.rb +30 -21
- data/lib/acfs/util.rb +1 -1
- data/lib/acfs/version.rb +4 -2
- data/spec/acfs/adapter/typhoeus_spec.rb +12 -4
- data/spec/acfs/collection_spec.rb +45 -33
- data/spec/acfs/configuration_spec.rb +9 -1
- data/spec/acfs/global_spec.rb +21 -3
- data/spec/acfs/middleware/json_spec.rb +63 -0
- data/spec/acfs/middleware/msgpack_spec.rb +60 -0
- data/spec/acfs/operation_spec.rb +10 -0
- data/spec/acfs/request/callbacks_spec.rb +8 -8
- data/spec/acfs/request_spec.rb +5 -5
- data/spec/acfs/resource/attributes/boolean_spec.rb +40 -9
- data/spec/acfs/resource/attributes/date_time_spec.rb +29 -35
- data/spec/acfs/resource/attributes/dict_spec.rb +75 -0
- data/spec/acfs/resource/attributes/float_spec.rb +48 -9
- data/spec/acfs/resource/attributes/integer_spec.rb +34 -0
- data/spec/acfs/resource/attributes/list_spec.rb +43 -19
- data/spec/acfs/resource/attributes/uuid_spec.rb +31 -54
- data/spec/acfs/resource/attributes_spec.rb +17 -31
- data/spec/acfs/resource/locatable_spec.rb +2 -2
- data/spec/acfs/resource/persistance_spec.rb +65 -34
- data/spec/acfs/resource/query_methods_spec.rb +87 -87
- data/spec/acfs/resource/validation_spec.rb +4 -5
- data/spec/acfs/response/formats_spec.rb +1 -1
- data/spec/acfs/response/status_spec.rb +1 -1
- data/spec/acfs/runner_spec.rb +28 -3
- data/spec/acfs/service/middleware_spec.rb +4 -20
- data/spec/acfs/service_spec.rb +3 -5
- data/spec/acfs/singleton_resource_spec.rb +1 -2
- data/spec/acfs/stub_spec.rb +137 -22
- data/spec/acfs_spec.rb +22 -19
- data/spec/spec_helper.rb +2 -1
- data/spec/support/service.rb +10 -6
- data/spec/support/shared/find_callbacks.rb +7 -7
- metadata +37 -30
- data/lib/acfs/middleware/json_decoder.rb +0 -16
- data/lib/acfs/middleware/json_encoder.rb +0 -20
- data/lib/acfs/middleware/msgpack_decoder.rb +0 -26
- data/lib/acfs/middleware/msgpack_encoder.rb +0 -19
- data/spec/acfs/middleware/json_decoder_spec.rb +0 -45
- data/spec/acfs/middleware/msgpack_decoder_spec.rb +0 -36
@@ -14,7 +14,7 @@ describe Acfs::Resource::QueryMethods do
|
|
14
14
|
name: 'Clare Customer', age: 24
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:action) {
|
17
|
+
let(:action) { ->(cb = nil) { model.find(1, &cb) } }
|
18
18
|
it_behaves_like 'a query method with multi-callback support'
|
19
19
|
|
20
20
|
it 'should load a single remote resource' do
|
@@ -44,7 +44,7 @@ describe Acfs::Resource::QueryMethods do
|
|
44
44
|
context 'with 404 response' do
|
45
45
|
before do
|
46
46
|
stub_request(:get, 'http://users.example.org/users/1')
|
47
|
-
.to_return response({error: 'not found'}, status: 404)
|
47
|
+
.to_return response({error: 'not found'}, {status: 404})
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should raise a NotFound error' do
|
@@ -95,7 +95,7 @@ describe Acfs::Resource::QueryMethods do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'should invoke callback after all models are loaded' do
|
98
|
-
block = proc{}
|
98
|
+
block = proc {}
|
99
99
|
expect(block).to receive(:call) do |users|
|
100
100
|
expect(users).to equal @users
|
101
101
|
expect(users.size).to be == 2
|
@@ -107,8 +107,8 @@ describe Acfs::Resource::QueryMethods do
|
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'should invoke multiple callback after all models are loaded' do
|
110
|
-
proc1 = proc{}
|
111
|
-
proc2 = proc{}
|
110
|
+
proc1 = proc {}
|
111
|
+
proc2 = proc {}
|
112
112
|
expect(proc1).to receive(:call) do |users|
|
113
113
|
expect(users).to equal @users
|
114
114
|
expect(users.size).to be == 2
|
@@ -137,7 +137,7 @@ describe Acfs::Resource::QueryMethods do
|
|
137
137
|
context 'with one 404 response' do
|
138
138
|
before do
|
139
139
|
stub_request(:get, 'http://users.example.org/users/1')
|
140
|
-
.to_return response({error: 'not found'}, status: 404)
|
140
|
+
.to_return response({error: 'not found'}, {status: 404})
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'should raise resource not found error' do
|
@@ -162,8 +162,8 @@ describe Acfs::Resource::QueryMethods do
|
|
162
162
|
end
|
163
163
|
|
164
164
|
it 'should invoke multiple callback after all models are loaded' do
|
165
|
-
proc1 = proc{}
|
166
|
-
proc2 = proc{}
|
165
|
+
proc1 = proc {}
|
166
|
+
proc2 = proc {}
|
167
167
|
expect(proc1).to receive(:call) do |computers|
|
168
168
|
expect(computers).to equal @computers
|
169
169
|
expect(computers.size).to be == 3
|
@@ -274,7 +274,7 @@ describe Acfs::Resource::QueryMethods do
|
|
274
274
|
end
|
275
275
|
|
276
276
|
it 'should invoke callback after model is loaded' do
|
277
|
-
block = proc{}
|
277
|
+
block = proc {}
|
278
278
|
|
279
279
|
expect(block).to receive(:call) do |user|
|
280
280
|
expect(user).to eql @user.__getobj__
|
@@ -287,8 +287,8 @@ describe Acfs::Resource::QueryMethods do
|
|
287
287
|
end
|
288
288
|
|
289
289
|
it 'should invoke multiple callbacks after model is loaded' do
|
290
|
-
proc1 = proc{}
|
291
|
-
proc2 = proc{}
|
290
|
+
proc1 = proc {}
|
291
|
+
proc2 = proc {}
|
292
292
|
|
293
293
|
expect(proc1).to receive(:call) do |user|
|
294
294
|
expect(user).to eql @user.__getobj__
|
@@ -340,7 +340,7 @@ describe Acfs::Resource::QueryMethods do
|
|
340
340
|
it { should be_nil }
|
341
341
|
|
342
342
|
it 'should invoke callback after model is loaded' do
|
343
|
-
block = proc{}
|
343
|
+
block = proc {}
|
344
344
|
|
345
345
|
expect(block).to receive(:call) do |user|
|
346
346
|
expect(user).to eql @user.__getobj__
|
@@ -352,8 +352,8 @@ describe Acfs::Resource::QueryMethods do
|
|
352
352
|
end
|
353
353
|
|
354
354
|
it 'should invoke multiple callbacks after model is loaded' do
|
355
|
-
proc1 = proc{}
|
356
|
-
proc2 = proc{}
|
355
|
+
proc1 = proc {}
|
356
|
+
proc2 = proc {}
|
357
357
|
|
358
358
|
expect(proc1).to receive(:call) do |user|
|
359
359
|
expect(user).to eql @user.__getobj__
|
@@ -393,7 +393,7 @@ describe Acfs::Resource::QueryMethods do
|
|
393
393
|
end
|
394
394
|
|
395
395
|
it 'should not invoke callback after model could not be loaded' do
|
396
|
-
block = proc{}
|
396
|
+
block = proc {}
|
397
397
|
|
398
398
|
expect(block).not_to receive(:call)
|
399
399
|
|
@@ -406,30 +406,30 @@ describe Acfs::Resource::QueryMethods do
|
|
406
406
|
describe '#each_page' do
|
407
407
|
context 'without parameters' do
|
408
408
|
before do
|
409
|
-
stub_request(:get, 'http://users.example.org/users')
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
stub_request(:get, 'http://users.example.org/users?page=2')
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
stub_request(:get, 'http://users.example.org/users?page=3')
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
stub_request(:get, 'http://users.example.org/users?page=4')
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
409
|
+
stub_request(:get, 'http://users.example.org/users')
|
410
|
+
.to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
411
|
+
headers: {
|
412
|
+
'X-Total-Pages' => '4',
|
413
|
+
'Link' => '<http://users.example.org/users?page=2>; rel="next"'
|
414
|
+
})
|
415
|
+
stub_request(:get, 'http://users.example.org/users?page=2')
|
416
|
+
.to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
417
|
+
headers: {
|
418
|
+
'X-Total-Pages' => '4',
|
419
|
+
'Link' => '<http://users.example.org/users?page=3>; rel="next"'
|
420
|
+
})
|
421
|
+
stub_request(:get, 'http://users.example.org/users?page=3')
|
422
|
+
.to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
423
|
+
headers: {
|
424
|
+
'X-Total-Pages' => '4',
|
425
|
+
'Link' => '<http://users.example.org/users?page=4>; rel="next"'
|
426
|
+
})
|
427
|
+
stub_request(:get, 'http://users.example.org/users?page=4')
|
428
|
+
.to_return response([{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
429
|
+
headers: {
|
430
|
+
'X-Total-Pages' => '4',
|
431
|
+
'Link' => ''
|
432
|
+
})
|
433
433
|
end
|
434
434
|
|
435
435
|
it 'should iterate all pages' do
|
@@ -448,30 +448,30 @@ describe Acfs::Resource::QueryMethods do
|
|
448
448
|
|
449
449
|
context 'with parameters' do
|
450
450
|
before do
|
451
|
-
stub_request(:get, 'http://users.example.org/users?param=bla')
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
stub_request(:get, 'http://users.example.org/users?where=fuu&page=2')
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
stub_request(:get, 'http://users.example.org/users?page=3')
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
stub_request(:get, 'http://users.example.org/users?page=4')
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
451
|
+
stub_request(:get, 'http://users.example.org/users?param=bla')
|
452
|
+
.to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
453
|
+
headers: {
|
454
|
+
'X-Total-Pages' => '4',
|
455
|
+
'Link' => '<http://users.example.org/users?where=fuu&page=2>; rel="next"'
|
456
|
+
})
|
457
|
+
stub_request(:get, 'http://users.example.org/users?where=fuu&page=2')
|
458
|
+
.to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
459
|
+
headers: {
|
460
|
+
'X-Total-Pages' => '4',
|
461
|
+
'Link' => '<http://users.example.org/users?page=3>; rel="next"'
|
462
|
+
})
|
463
|
+
stub_request(:get, 'http://users.example.org/users?page=3')
|
464
|
+
.to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
465
|
+
headers: {
|
466
|
+
'X-Total-Pages' => '4',
|
467
|
+
'Link' => '<http://users.example.org/users?page=4>; rel="next"'
|
468
|
+
})
|
469
|
+
stub_request(:get, 'http://users.example.org/users?page=4')
|
470
|
+
.to_return response([{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
471
|
+
headers: {
|
472
|
+
'X-Total-Pages' => '4',
|
473
|
+
'Link' => ''
|
474
|
+
})
|
475
475
|
end
|
476
476
|
|
477
477
|
it 'should call first page with params and follow relations' do
|
@@ -492,30 +492,30 @@ describe Acfs::Resource::QueryMethods do
|
|
492
492
|
describe '#each_item' do
|
493
493
|
context 'without parameters' do
|
494
494
|
before do
|
495
|
-
stub_request(:get, 'http://users.example.org/users')
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
stub_request(:get, 'http://users.example.org/users?page=2')
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
stub_request(:get, 'http://users.example.org/users?page=3')
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
stub_request(:get, 'http://users.example.org/users?page=4')
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
495
|
+
stub_request(:get, 'http://users.example.org/users')
|
496
|
+
.to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
497
|
+
headers: {
|
498
|
+
'X-Total-Pages' => '4',
|
499
|
+
'Link' => '<http://users.example.org/users?page=2>; rel="next"'
|
500
|
+
})
|
501
|
+
stub_request(:get, 'http://users.example.org/users?page=2')
|
502
|
+
.to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
503
|
+
headers: {
|
504
|
+
'X-Total-Pages' => '4',
|
505
|
+
'Link' => '<http://users.example.org/users?page=3>; rel="next"'
|
506
|
+
})
|
507
|
+
stub_request(:get, 'http://users.example.org/users?page=3')
|
508
|
+
.to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}, {id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
509
|
+
headers: {
|
510
|
+
'X-Total-Pages' => '4',
|
511
|
+
'Link' => '<http://users.example.org/users?page=4>; rel="next"'
|
512
|
+
})
|
513
|
+
stub_request(:get, 'http://users.example.org/users?page=4')
|
514
|
+
.to_return response([{id: 5, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
515
|
+
headers: {
|
516
|
+
'X-Total-Pages' => '4',
|
517
|
+
'Link' => ''
|
518
|
+
})
|
519
519
|
end
|
520
520
|
|
521
521
|
it 'should iterate all pages' do
|
@@ -23,7 +23,7 @@ describe Acfs::Resource::Validation do
|
|
23
23
|
after { Acfs::Stub.disable }
|
24
24
|
|
25
25
|
before do
|
26
|
-
Acfs::Stub.resource MyUser, :create,
|
26
|
+
Acfs::Stub.resource MyUser, :create, return: {errors: {name: ['can\'t be blank']}}, raise: 422
|
27
27
|
end
|
28
28
|
|
29
29
|
let(:params) { {} }
|
@@ -34,7 +34,7 @@ describe Acfs::Resource::Validation do
|
|
34
34
|
|
35
35
|
it 'should not override errors' do
|
36
36
|
subject.valid?
|
37
|
-
expect(subject.errors.to_hash).to eq(
|
37
|
+
expect(subject.errors.to_hash).to eq(name: ['can\'t be blank'])
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -73,7 +73,7 @@ describe Acfs::Resource::Validation do
|
|
73
73
|
let(:resource) { MyUser.create params }
|
74
74
|
subject { resource }
|
75
75
|
|
76
|
-
its(:errors) { expect(subject.errors.to_hash).to eq(
|
76
|
+
its(:errors) { expect(subject.errors.to_hash).to eq(name: ['can\'t be blank']) }
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -96,7 +96,7 @@ describe Acfs::Resource::Validation do
|
|
96
96
|
|
97
97
|
context 'on changed resource' do
|
98
98
|
before { model.loaded! }
|
99
|
-
let(:model) { super().tap {
|
99
|
+
let(:model) { super().tap {|m| m.id = 1 } }
|
100
100
|
|
101
101
|
it 'should validate with `save` context' do
|
102
102
|
expect(model).to receive(:valid?).with(:save).and_call_original
|
@@ -106,6 +106,5 @@ describe Acfs::Resource::Validation do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
describe 'validates with context' do
|
109
|
-
|
110
109
|
end
|
111
110
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Acfs::Response::Formats do
|
4
4
|
let(:status) { 200 }
|
5
5
|
let(:mime_type) { 'application/unknown' }
|
6
|
-
let(:headers) { {
|
6
|
+
let(:headers) { {'Content-Type' => mime_type} }
|
7
7
|
let(:request) { Acfs::Request.new 'fubar' }
|
8
8
|
let(:body) { nil }
|
9
9
|
let(:response) { Acfs::Response.new request, status: status, headers: headers, body: body }
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Acfs::Response::Status do
|
4
4
|
let(:status) { 200 }
|
5
5
|
let(:mime_type) { 'application/unknown' }
|
6
|
-
let(:headers) { {
|
6
|
+
let(:headers) { {'Content-Type' => mime_type} }
|
7
7
|
let(:request) { Acfs::Request.new 'fubar' }
|
8
8
|
let(:body) { nil }
|
9
9
|
let(:response) { Acfs::Response.new request, status: status, headers: headers, body: body }
|
data/spec/acfs/runner_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class NullAdapter < Acfs::Adapter::Base
|
4
|
-
|
5
4
|
# Start processing queued requests.
|
6
5
|
#
|
7
6
|
def start
|
@@ -37,6 +36,7 @@ describe ::Acfs::Runner do
|
|
37
36
|
let(:adapter) { ::NullAdapter.new }
|
38
37
|
let(:runner) { ::Acfs::Runner.new adapter }
|
39
38
|
let(:collector) { NotificationCollector.new }
|
39
|
+
let(:collector2) { NotificationCollector.new }
|
40
40
|
|
41
41
|
after do
|
42
42
|
::ActiveSupport::Notifications.notifier = \
|
@@ -45,13 +45,15 @@ describe ::Acfs::Runner do
|
|
45
45
|
|
46
46
|
describe '#instrumentation' do
|
47
47
|
before do
|
48
|
-
::ActiveSupport::Notifications.subscribe
|
48
|
+
::ActiveSupport::Notifications.subscribe(/^acfs\.runner/, collector)
|
49
|
+
::ActiveSupport::Notifications.subscribe(/^acfs\.operation/, collector2)
|
49
50
|
end
|
50
51
|
|
51
52
|
describe '#process' do
|
52
53
|
it 'should trigger event' do
|
53
54
|
runner.process ::Acfs::Operation.new MyUser, :read, params: {id: 0}
|
54
55
|
expect(collector.events).to have(1).items
|
56
|
+
expect(collector2.events).to have(1).items
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -59,14 +61,37 @@ describe ::Acfs::Runner do
|
|
59
61
|
it 'should trigger event' do
|
60
62
|
runner.run ::Acfs::Operation.new MyUser, :read, params: {id: 0}
|
61
63
|
expect(collector.events).to have(1).items
|
64
|
+
expect(collector2.events).to have(0).items
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
65
68
|
describe '#enqueue' do
|
66
69
|
it 'should trigger event' do
|
67
|
-
runner.
|
70
|
+
runner.enqueue ::Acfs::Operation.new MyUser, :read, params: {id: 0}
|
68
71
|
expect(collector.events).to have(1).items
|
72
|
+
expect(collector2.events).to have(0).items
|
69
73
|
end
|
70
74
|
end
|
71
75
|
end
|
76
|
+
|
77
|
+
describe '#run' do
|
78
|
+
before do
|
79
|
+
expect_any_instance_of(UserService).to receive(:prepare).and_return nil
|
80
|
+
end
|
81
|
+
it 'it should not do requests when a middleware aborted' do
|
82
|
+
expect(adapter).to_not receive :run
|
83
|
+
runner.run ::Acfs::Operation.new MyUser, :read, params: {id: 0}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#enqueue' do
|
88
|
+
before do
|
89
|
+
expect_any_instance_of(UserService).to receive(:prepare).and_return nil
|
90
|
+
end
|
91
|
+
it 'it should not do requests when a middleware aborted' do
|
92
|
+
expect(adapter).to_not receive :queue
|
93
|
+
runner.enqueue ::Acfs::Operation.new MyUser, :read, params: {id: 0}
|
94
|
+
runner.start
|
95
|
+
end
|
96
|
+
end
|
72
97
|
end
|
@@ -6,44 +6,28 @@ end
|
|
6
6
|
describe Acfs::Service::Middleware do
|
7
7
|
let(:srv_class) { Class.new(Acfs::Service) }
|
8
8
|
let(:options) { {} }
|
9
|
-
let(:service) { srv_class.new options }
|
10
9
|
let(:middleware) { TestMiddleware }
|
11
10
|
|
12
11
|
describe '.use' do
|
13
|
-
let(:options) { {
|
12
|
+
let(:options) { {abc: 'cde'} }
|
14
13
|
|
15
14
|
it 'should add middleware to list' do
|
16
15
|
srv_class.use middleware
|
17
16
|
|
18
|
-
expect(srv_class.
|
17
|
+
expect(srv_class.middleware).to include(middleware)
|
19
18
|
end
|
20
19
|
|
21
20
|
it 'should add middleware to stack' do
|
22
21
|
srv_class.use middleware
|
23
22
|
|
24
|
-
expect(srv_class.middleware).to be_a(middleware)
|
23
|
+
expect(srv_class.middleware.build(1)).to be_a(middleware)
|
25
24
|
end
|
26
25
|
|
27
26
|
it 'should instantiate middleware object' do
|
28
27
|
expect(middleware).to receive(:new).with(anything, options)
|
29
28
|
|
30
29
|
srv_class.use middleware, options
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '.clear' do
|
35
|
-
before { srv_class.use middleware }
|
36
|
-
|
37
|
-
it 'should clear middleware list' do
|
38
|
-
srv_class.clear
|
39
|
-
|
40
|
-
expect(srv_class.instance_variable_get(:@middlewares)).to be_empty
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should reset middleware stack' do
|
44
|
-
srv_class.clear
|
45
|
-
|
46
|
-
expect(srv_class.instance_variable_get(:@middleware)).to be_nil
|
30
|
+
srv_class.middleware.build
|
47
31
|
end
|
48
32
|
end
|
49
33
|
end
|
data/spec/acfs/service_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Acfs::Service do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '#initialize' do
|
13
|
-
let(:options) { {
|
13
|
+
let(:options) { {path: 'abc', key: 'value'} }
|
14
14
|
|
15
15
|
it 'should set options' do
|
16
16
|
expect(service.options).to eq(options)
|
@@ -19,14 +19,14 @@ describe Acfs::Service do
|
|
19
19
|
|
20
20
|
describe '#location' do
|
21
21
|
let(:resource) { Class.new }
|
22
|
-
before { allow(resource).to receive(:location_default_path, &proc{|
|
22
|
+
before { allow(resource).to receive(:location_default_path, &proc{|_a, p| p}) }
|
23
23
|
|
24
24
|
it 'should extract resource path name from given class' do
|
25
25
|
expect(service.location(resource).to_s).to eq('/classes')
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'with path options' do
|
29
|
-
let(:options) { {
|
29
|
+
let(:options) { {path: 'abc'} }
|
30
30
|
|
31
31
|
it 'should have custom resource path' do
|
32
32
|
expect(service.location(resource).to_s).to eq('/abc')
|
@@ -35,13 +35,11 @@ describe Acfs::Service do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '.base_url' do
|
38
|
-
|
39
38
|
before do
|
40
39
|
Acfs::Configuration.current.locate :test, 'http://abc.de/api/v1'
|
41
40
|
end
|
42
41
|
|
43
42
|
it 'should return configured URI for service' do
|
44
|
-
|
45
43
|
expect(srv_class.base_url).to eq('http://abc.de/api/v1')
|
46
44
|
end
|
47
45
|
end
|