acfs 0.50.0 → 1.0.0.dev.1.b297

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +13 -5
  2. data/CHANGELOG.md +0 -80
  3. data/README.md +9 -8
  4. data/acfs.gemspec +7 -7
  5. data/lib/acfs.rb +5 -7
  6. data/lib/acfs/adapter/base.rb +2 -0
  7. data/lib/acfs/adapter/typhoeus.rb +13 -17
  8. data/lib/acfs/collections/paginatable.rb +10 -10
  9. data/lib/acfs/configuration.rb +5 -4
  10. data/lib/acfs/errors.rb +9 -10
  11. data/lib/acfs/global.rb +7 -16
  12. data/lib/acfs/location.rb +11 -11
  13. data/lib/acfs/middleware/base.rb +2 -1
  14. data/lib/acfs/middleware/json_decoder.rb +16 -0
  15. data/lib/acfs/middleware/json_encoder.rb +20 -0
  16. data/lib/acfs/middleware/logger.rb +2 -0
  17. data/lib/acfs/middleware/msgpack_decoder.rb +26 -0
  18. data/lib/acfs/middleware/msgpack_encoder.rb +19 -0
  19. data/lib/acfs/middleware/print.rb +2 -0
  20. data/lib/acfs/operation.rb +5 -5
  21. data/lib/acfs/request.rb +4 -4
  22. data/lib/acfs/request/callbacks.rb +3 -2
  23. data/lib/acfs/resource.rb +2 -2
  24. data/lib/acfs/resource/attributes.rb +38 -11
  25. data/lib/acfs/resource/attributes/base.rb +19 -10
  26. data/lib/acfs/resource/attributes/boolean.rb +8 -10
  27. data/lib/acfs/resource/attributes/date_time.rb +9 -6
  28. data/lib/acfs/resource/attributes/float.rb +5 -11
  29. data/lib/acfs/resource/attributes/integer.rb +5 -7
  30. data/lib/acfs/resource/attributes/list.rb +6 -13
  31. data/lib/acfs/resource/attributes/string.rb +5 -3
  32. data/lib/acfs/resource/attributes/uuid.rb +17 -8
  33. data/lib/acfs/resource/dirty.rb +15 -3
  34. data/lib/acfs/resource/loadable.rb +1 -0
  35. data/lib/acfs/resource/locatable.rb +4 -0
  36. data/lib/acfs/resource/operational.rb +2 -0
  37. data/lib/acfs/resource/persistence.rb +17 -17
  38. data/lib/acfs/resource/query_methods.rb +7 -8
  39. data/lib/acfs/resource/service.rb +2 -0
  40. data/lib/acfs/resource/validation.rb +4 -4
  41. data/lib/acfs/response.rb +2 -1
  42. data/lib/acfs/response/formats.rb +3 -2
  43. data/lib/acfs/response/status.rb +5 -3
  44. data/lib/acfs/runner.rb +11 -21
  45. data/lib/acfs/service.rb +6 -4
  46. data/lib/acfs/service/middleware.rb +30 -20
  47. data/lib/acfs/singleton_resource.rb +2 -0
  48. data/lib/acfs/stub.rb +21 -30
  49. data/lib/acfs/util.rb +1 -1
  50. data/lib/acfs/version.rb +4 -6
  51. data/spec/acfs/adapter/typhoeus_spec.rb +4 -12
  52. data/spec/acfs/collection_spec.rb +33 -45
  53. data/spec/acfs/configuration_spec.rb +1 -9
  54. data/spec/acfs/global_spec.rb +3 -21
  55. data/spec/acfs/middleware/json_decoder_spec.rb +45 -0
  56. data/spec/acfs/middleware/msgpack_decoder_spec.rb +36 -0
  57. data/spec/acfs/request/callbacks_spec.rb +8 -8
  58. data/spec/acfs/request_spec.rb +5 -5
  59. data/spec/acfs/resource/attributes/boolean_spec.rb +9 -40
  60. data/spec/acfs/resource/attributes/date_time_spec.rb +35 -29
  61. data/spec/acfs/resource/attributes/float_spec.rb +9 -48
  62. data/spec/acfs/resource/attributes/list_spec.rb +19 -43
  63. data/spec/acfs/resource/attributes/uuid_spec.rb +54 -31
  64. data/spec/acfs/resource/attributes_spec.rb +31 -17
  65. data/spec/acfs/resource/locatable_spec.rb +2 -2
  66. data/spec/acfs/resource/persistance_spec.rb +34 -65
  67. data/spec/acfs/resource/query_methods_spec.rb +90 -97
  68. data/spec/acfs/resource/validation_spec.rb +5 -4
  69. data/spec/acfs/response/formats_spec.rb +4 -4
  70. data/spec/acfs/response/status_spec.rb +1 -1
  71. data/spec/acfs/runner_spec.rb +3 -28
  72. data/spec/acfs/service/middleware_spec.rb +20 -4
  73. data/spec/acfs/service_spec.rb +5 -3
  74. data/spec/acfs/singleton_resource_spec.rb +2 -1
  75. data/spec/acfs/stub_spec.rb +22 -137
  76. data/spec/acfs_spec.rb +19 -22
  77. data/spec/spec_helper.rb +2 -3
  78. data/spec/support/service.rb +6 -10
  79. data/spec/support/shared/find_callbacks.rb +7 -7
  80. metadata +36 -43
  81. data/lib/acfs/middleware/json.rb +0 -27
  82. data/lib/acfs/middleware/msgpack.rb +0 -30
  83. data/lib/acfs/middleware/serializer.rb +0 -39
  84. data/lib/acfs/resource/attributes/dict.rb +0 -37
  85. data/lib/acfs/service/middleware/stack.rb +0 -63
  86. data/spec/acfs/middleware/json_spec.rb +0 -63
  87. data/spec/acfs/middleware/msgpack_spec.rb +0 -60
  88. data/spec/acfs/operation_spec.rb +0 -10
  89. data/spec/acfs/resource/attributes/dict_spec.rb +0 -75
  90. data/spec/acfs/resource/attributes/integer_spec.rb +0 -34
@@ -14,7 +14,7 @@ describe Acfs::Resource::QueryMethods do
14
14
  name: 'Clare Customer', age: 24
15
15
  end
16
16
 
17
- let(:action) { ->(cb = nil) { model.find(1, &cb) } }
17
+ let(:action) { lambda{|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
- .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
- })
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
- .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
- })
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,48 +492,41 @@ 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
- .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
- })
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
522
- indices = []
522
+ indecies = []
523
523
  model.each_item do |item|
524
524
  expect(item).to be_a MyUser
525
- indices << item.id
525
+ indecies << item.id
526
526
  end
527
527
  Acfs.run
528
528
 
529
- expect(indices).to eq [1, 2, 3, 4, 5]
530
- end
531
-
532
- it 'should pass the collection to the provided block' do
533
- model.each_item do |_item, collection|
534
- expect(collection).to be_a Acfs::Collection
535
- end
536
- Acfs.run
529
+ expect(indecies).to eq [1, 2, 3, 4, 5]
537
530
  end
538
531
  end
539
532
  end
@@ -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, return: {errors: {name: ['can\'t be blank']}}, raise: 422
26
+ Acfs::Stub.resource MyUser, :create, with: {}, 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(name: ['can\'t be blank'])
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(name: ['can\'t be blank']) }
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 {|m| m.id = 1 } }
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,5 +106,6 @@ describe Acfs::Resource::Validation do
106
106
  end
107
107
 
108
108
  describe 'validates with context' do
109
+
109
110
  end
110
111
  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) { {'Content-Type' => mime_type} }
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 }
@@ -12,7 +12,7 @@ describe Acfs::Response::Formats do
12
12
  let(:headers) { {} }
13
13
 
14
14
  it "should fallback on 'text/plain'" do
15
- expect(response.content_type).to be == Mime[:text]
15
+ expect(response.content_type).to be == Mime::TEXT
16
16
  end
17
17
  end
18
18
 
@@ -21,7 +21,7 @@ describe Acfs::Response::Formats do
21
21
 
22
22
  describe '#content_type' do
23
23
  it 'should return Mime::JSON' do
24
- expect(response.content_type).to be == Mime[:json]
24
+ expect(response.content_type).to be == Mime::JSON
25
25
  end
26
26
  end
27
27
 
@@ -36,7 +36,7 @@ describe Acfs::Response::Formats do
36
36
 
37
37
  describe '#content_type' do
38
38
  it 'should return Mime::JSON' do
39
- expect(response.content_type).to be == Mime[:json]
39
+ expect(response.content_type).to be == Mime::JSON
40
40
  end
41
41
  end
42
42
 
@@ -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) { {'Content-Type' => mime_type} }
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 }
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class NullAdapter < Acfs::Adapter::Base
4
+
4
5
  # Start processing queued requests.
5
6
  #
6
7
  def start
@@ -36,7 +37,6 @@ describe ::Acfs::Runner do
36
37
  let(:adapter) { ::NullAdapter.new }
37
38
  let(:runner) { ::Acfs::Runner.new adapter }
38
39
  let(:collector) { NotificationCollector.new }
39
- let(:collector2) { NotificationCollector.new }
40
40
 
41
41
  after do
42
42
  ::ActiveSupport::Notifications.notifier = \
@@ -45,15 +45,13 @@ describe ::Acfs::Runner do
45
45
 
46
46
  describe '#instrumentation' do
47
47
  before do
48
- ::ActiveSupport::Notifications.subscribe(/^acfs\.runner/, collector)
49
- ::ActiveSupport::Notifications.subscribe(/^acfs\.operation/, collector2)
48
+ ::ActiveSupport::Notifications.subscribe /^acfs\.runner/, collector
50
49
  end
51
50
 
52
51
  describe '#process' do
53
52
  it 'should trigger event' do
54
53
  runner.process ::Acfs::Operation.new MyUser, :read, params: {id: 0}
55
54
  expect(collector.events).to have(1).items
56
- expect(collector2.events).to have(1).items
57
55
  end
58
56
  end
59
57
 
@@ -61,37 +59,14 @@ describe ::Acfs::Runner do
61
59
  it 'should trigger event' do
62
60
  runner.run ::Acfs::Operation.new MyUser, :read, params: {id: 0}
63
61
  expect(collector.events).to have(1).items
64
- expect(collector2.events).to have(0).items
65
62
  end
66
63
  end
67
64
 
68
65
  describe '#enqueue' do
69
66
  it 'should trigger event' do
70
- runner.enqueue ::Acfs::Operation.new MyUser, :read, params: {id: 0}
67
+ runner.run ::Acfs::Operation.new MyUser, :read, params: {id: 0}
71
68
  expect(collector.events).to have(1).items
72
- expect(collector2.events).to have(0).items
73
69
  end
74
70
  end
75
71
  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
97
72
  end
@@ -6,28 +6,44 @@ 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 }
9
10
  let(:middleware) { TestMiddleware }
10
11
 
11
12
  describe '.use' do
12
- let(:options) { {abc: 'cde'} }
13
+ let(:options) { { abc: 'cde' } }
13
14
 
14
15
  it 'should add middleware to list' do
15
16
  srv_class.use middleware
16
17
 
17
- expect(srv_class.middleware).to include(middleware)
18
+ expect(srv_class.instance_variable_get(:@middlewares)).to include(middleware)
18
19
  end
19
20
 
20
21
  it 'should add middleware to stack' do
21
22
  srv_class.use middleware
22
23
 
23
- expect(srv_class.middleware.build(1)).to be_a(middleware)
24
+ expect(srv_class.middleware).to be_a(middleware)
24
25
  end
25
26
 
26
27
  it 'should instantiate middleware object' do
27
28
  expect(middleware).to receive(:new).with(anything, options)
28
29
 
29
30
  srv_class.use middleware, options
30
- srv_class.middleware.build
31
+ end
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
31
47
  end
32
48
  end
33
49
  end