acfs 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -0
- data/README.md +3 -4
- data/acfs.gemspec +19 -10
- data/lib/acfs.rb +2 -0
- data/lib/acfs/adapter/base.rb +6 -8
- data/lib/acfs/adapter/typhoeus.rb +26 -7
- data/lib/acfs/collection.rb +2 -1
- data/lib/acfs/collections/paginatable.rb +2 -1
- data/lib/acfs/configuration.rb +14 -7
- data/lib/acfs/errors.rb +33 -12
- data/lib/acfs/global.rb +12 -2
- data/lib/acfs/location.rb +9 -5
- data/lib/acfs/middleware/base.rb +5 -1
- data/lib/acfs/middleware/json.rb +2 -0
- data/lib/acfs/middleware/logger.rb +2 -0
- data/lib/acfs/middleware/msgpack.rb +2 -0
- data/lib/acfs/middleware/print.rb +2 -0
- data/lib/acfs/middleware/serializer.rb +2 -0
- data/lib/acfs/operation.rb +5 -3
- data/lib/acfs/request.rb +3 -0
- data/lib/acfs/request/callbacks.rb +5 -1
- data/lib/acfs/resource.rb +2 -0
- data/lib/acfs/resource/attributes.rb +3 -2
- data/lib/acfs/resource/attributes/base.rb +2 -1
- data/lib/acfs/resource/attributes/boolean.rb +2 -0
- data/lib/acfs/resource/attributes/date_time.rb +2 -1
- data/lib/acfs/resource/attributes/dict.rb +2 -0
- data/lib/acfs/resource/attributes/float.rb +5 -3
- data/lib/acfs/resource/attributes/integer.rb +2 -0
- data/lib/acfs/resource/attributes/list.rb +2 -0
- data/lib/acfs/resource/attributes/string.rb +2 -0
- data/lib/acfs/resource/attributes/uuid.rb +4 -3
- data/lib/acfs/resource/dirty.rb +2 -0
- data/lib/acfs/resource/initialization.rb +2 -0
- data/lib/acfs/resource/loadable.rb +2 -0
- data/lib/acfs/resource/locatable.rb +10 -6
- data/lib/acfs/resource/operational.rb +2 -1
- data/lib/acfs/resource/persistence.rb +7 -4
- data/lib/acfs/resource/query_methods.rb +5 -3
- data/lib/acfs/resource/service.rb +3 -1
- data/lib/acfs/resource/validation.rb +3 -1
- data/lib/acfs/response.rb +2 -0
- data/lib/acfs/response/formats.rb +2 -0
- data/lib/acfs/response/status.rb +3 -1
- data/lib/acfs/rspec.rb +2 -0
- data/lib/acfs/runner.rb +6 -1
- data/lib/acfs/service.rb +8 -2
- data/lib/acfs/service/middleware.rb +2 -0
- data/lib/acfs/service/middleware/stack.rb +5 -3
- data/lib/acfs/singleton_resource.rb +4 -2
- data/lib/acfs/stub.rb +33 -11
- data/lib/acfs/util.rb +2 -0
- data/lib/acfs/version.rb +3 -1
- data/lib/acfs/yard.rb +1 -0
- data/spec/acfs/adapter/typhoeus_spec.rb +30 -3
- data/spec/acfs/collection_spec.rb +7 -5
- data/spec/acfs/configuration_spec.rb +2 -0
- data/spec/acfs/global_spec.rb +48 -1
- data/spec/acfs/location_spec.rb +25 -0
- data/spec/acfs/middleware/json_spec.rb +2 -0
- data/spec/acfs/middleware/msgpack_spec.rb +2 -0
- data/spec/acfs/operation_spec.rb +2 -0
- data/spec/acfs/request/callbacks_spec.rb +2 -0
- data/spec/acfs/request_spec.rb +3 -1
- data/spec/acfs/resource/attributes/boolean_spec.rb +2 -0
- data/spec/acfs/resource/attributes/date_time_spec.rb +2 -0
- data/spec/acfs/resource/attributes/dict_spec.rb +4 -2
- data/spec/acfs/resource/attributes/float_spec.rb +2 -0
- data/spec/acfs/resource/attributes/integer_spec.rb +2 -0
- data/spec/acfs/resource/attributes/list_spec.rb +5 -3
- data/spec/acfs/resource/attributes/uuid_spec.rb +2 -0
- data/spec/acfs/resource/attributes_spec.rb +6 -4
- data/spec/acfs/resource/dirty_spec.rb +2 -0
- data/spec/acfs/resource/initialization_spec.rb +8 -2
- data/spec/acfs/resource/loadable_spec.rb +2 -0
- data/spec/acfs/resource/locatable_spec.rb +2 -0
- data/spec/acfs/resource/persistance_spec.rb +10 -4
- data/spec/acfs/resource/query_methods_spec.rb +25 -18
- data/spec/acfs/resource/validation_spec.rb +2 -0
- data/spec/acfs/response/formats_spec.rb +3 -1
- data/spec/acfs/response/status_spec.rb +2 -0
- data/spec/acfs/runner_spec.rb +6 -8
- data/spec/acfs/service/middleware_spec.rb +2 -0
- data/spec/acfs/service_spec.rb +3 -1
- data/spec/acfs/singleton_resource_spec.rb +2 -0
- data/spec/acfs/stub_spec.rb +2 -0
- data/spec/acfs_spec.rb +2 -0
- data/spec/spec_helper.rb +11 -6
- data/spec/support/hash.rb +2 -0
- data/spec/support/response.rb +2 -0
- data/spec/support/service.rb +1 -0
- data/spec/support/shared/find_callbacks.rb +2 -0
- metadata +12 -11
data/spec/acfs/operation_spec.rb
CHANGED
data/spec/acfs/request_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Acfs::Request do
|
@@ -18,7 +20,7 @@ describe Acfs::Request do
|
|
18
20
|
let(:params) { {id: 10} }
|
19
21
|
|
20
22
|
it 'should return URL without query' do
|
21
|
-
expect(request.url).to be ==
|
23
|
+
expect(request.url).to be == url.to_s
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Acfs::Resource::Attributes::Dict do
|
@@ -13,12 +15,12 @@ describe Acfs::Resource::Attributes::Dict do
|
|
13
15
|
|
14
16
|
context 'with blank string (I)' do
|
15
17
|
let(:value) { '' }
|
16
|
-
it { expect(subject.call).to eq
|
18
|
+
it { expect(subject.call).to eq({}) }
|
17
19
|
end
|
18
20
|
|
19
21
|
context 'with blank string (II)' do
|
20
22
|
let(:value) { " \t" }
|
21
|
-
it { expect(subject.call).to eq
|
23
|
+
it { expect(subject.call).to eq({}) }
|
22
24
|
end
|
23
25
|
|
24
26
|
context 'with hash' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Acfs::Resource::Attributes::List do
|
@@ -13,16 +15,16 @@ describe Acfs::Resource::Attributes::List do
|
|
13
15
|
|
14
16
|
context 'with blank string (I)' do
|
15
17
|
let(:value) { '' }
|
16
|
-
it { expect(subject.call).to eq
|
18
|
+
it { expect(subject.call).to eq [] }
|
17
19
|
end
|
18
20
|
|
19
21
|
context 'with blank string (II)' do
|
20
22
|
let(:value) { " \t" }
|
21
|
-
it { expect(subject.call).to eq
|
23
|
+
it { expect(subject.call).to eq [] }
|
22
24
|
end
|
23
25
|
|
24
26
|
context 'with array' do
|
25
|
-
let(:value) { %w
|
27
|
+
let(:value) { %w[abc cde efg] }
|
26
28
|
it { expect(subject.call).to eq value }
|
27
29
|
end
|
28
30
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Acfs::Resource::Attributes do
|
@@ -52,7 +54,7 @@ describe Acfs::Resource::Attributes do
|
|
52
54
|
let(:action) { -> { m.write_attributes(*args) } }
|
53
55
|
subject { action }
|
54
56
|
|
55
|
-
it 'should update attributes'
|
57
|
+
it 'should update attributes' do
|
56
58
|
should change(m, :attributes)
|
57
59
|
.from(name: 'The Great John', age: 25)
|
58
60
|
.to(name: 'The Great James', age: 25)
|
@@ -70,7 +72,7 @@ describe Acfs::Resource::Attributes do
|
|
70
72
|
|
71
73
|
it { should_not raise_error }
|
72
74
|
|
73
|
-
it 'should update known attributes and store unknown'
|
75
|
+
it 'should update known attributes and store unknown' do
|
74
76
|
should change(m, :attributes)
|
75
77
|
.from(name: 'The Great John', age: 25)
|
76
78
|
.to(name: 'The Great James', age: 25, born_at: 'today')
|
@@ -85,7 +87,7 @@ describe Acfs::Resource::Attributes do
|
|
85
87
|
expect do
|
86
88
|
begin
|
87
89
|
subject.call
|
88
|
-
rescue
|
90
|
+
rescue StandardError
|
89
91
|
true
|
90
92
|
end
|
91
93
|
end.to_not change(m, :attributes)
|
@@ -171,7 +173,7 @@ describe Acfs::Resource::Attributes do
|
|
171
173
|
end
|
172
174
|
|
173
175
|
it 'includes superclass attributes' do
|
174
|
-
expect(submodel.attributes.keys).to match_array %w
|
176
|
+
expect(submodel.attributes.keys).to match_array %w[age born_at]
|
175
177
|
end
|
176
178
|
end
|
177
179
|
end
|
@@ -1,11 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'Acfs::Resource::Initialization' do
|
4
6
|
let(:model) do
|
5
7
|
Class.new(Acfs::Resource).tap do |c|
|
6
8
|
c.class_eval do
|
7
|
-
attr_accessor :name
|
8
|
-
|
9
|
+
attr_accessor :name
|
10
|
+
attr_reader :age
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
attr_writer :age
|
9
15
|
end
|
10
16
|
end
|
11
17
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Acfs::Resource::Persistence do
|
@@ -226,8 +228,12 @@ describe Acfs::Resource::Persistence do
|
|
226
228
|
|
227
229
|
it 'should set local errors hash' do
|
228
230
|
model.name = ''
|
229
|
-
|
230
|
-
|
231
|
+
begin
|
232
|
+
model.save!
|
233
|
+
rescue StandardError
|
234
|
+
nil
|
235
|
+
end
|
236
|
+
expect(model.errors.to_hash).to be == {name: %w[required]}
|
231
237
|
end
|
232
238
|
end
|
233
239
|
|
@@ -265,7 +271,7 @@ describe Acfs::Resource::Persistence do
|
|
265
271
|
it 'should raise an error' do
|
266
272
|
expect { model_class.create! data }.to \
|
267
273
|
raise_error(::Acfs::InvalidResource) do |error|
|
268
|
-
expect(error.errors).to be == {'name' => %w
|
274
|
+
expect(error.errors).to be == {'name' => %w[required]}
|
269
275
|
end
|
270
276
|
end
|
271
277
|
end
|
@@ -295,7 +301,7 @@ describe Acfs::Resource::Persistence do
|
|
295
301
|
end
|
296
302
|
|
297
303
|
it 'should contain error hash' do
|
298
|
-
expect(subject.errors.to_hash).to eq name: %w
|
304
|
+
expect(subject.errors.to_hash).to eq name: %w[required]
|
299
305
|
end
|
300
306
|
end
|
301
307
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Acfs::Resource::QueryMethods do
|
@@ -158,7 +160,8 @@ describe Acfs::Resource::QueryMethods do
|
|
158
160
|
.to_return response [
|
159
161
|
{id: 1, type: 'PC'},
|
160
162
|
{id: 2, type: 'Computer'},
|
161
|
-
{id: 3, type: 'Mac'}
|
163
|
+
{id: 3, type: 'Mac'}
|
164
|
+
]
|
162
165
|
end
|
163
166
|
|
164
167
|
it 'should invoke multiple callback after all models are loaded' do
|
@@ -209,7 +212,8 @@ describe Acfs::Resource::QueryMethods do
|
|
209
212
|
.to_return response [
|
210
213
|
{id: 1, type: 'MyUser'},
|
211
214
|
{id: 2, type: 'Computer'},
|
212
|
-
{id: 3, type: 'Mac'}
|
215
|
+
{id: 3, type: 'Mac'}
|
216
|
+
]
|
213
217
|
end
|
214
218
|
it_behaves_like 'with invalid type'
|
215
219
|
end
|
@@ -220,7 +224,8 @@ describe Acfs::Resource::QueryMethods do
|
|
220
224
|
.to_return response [
|
221
225
|
{id: 1, type: 'PC'},
|
222
226
|
{id: 2, type: 'noValidType'},
|
223
|
-
{id: 3, type: 'Mac'}
|
227
|
+
{id: 3, type: 'Mac'}
|
228
|
+
]
|
224
229
|
end
|
225
230
|
it_behaves_like 'with invalid type'
|
226
231
|
end
|
@@ -231,7 +236,8 @@ describe Acfs::Resource::QueryMethods do
|
|
231
236
|
.to_return response [
|
232
237
|
{id: 1, type: 'PC'},
|
233
238
|
{id: 2, type: 'Computer'},
|
234
|
-
{id: 3, type: 42}
|
239
|
+
{id: 3, type: 42}
|
240
|
+
]
|
235
241
|
end
|
236
242
|
it_behaves_like 'with invalid type'
|
237
243
|
end
|
@@ -270,7 +276,8 @@ describe Acfs::Resource::QueryMethods do
|
|
270
276
|
.to_return response [
|
271
277
|
{id: 1, name: 'Mike', age: 24},
|
272
278
|
{id: 4, type: 'Maria', age: 24},
|
273
|
-
{id: 7, type: 'James', age: 24}
|
279
|
+
{id: 7, type: 'James', age: 24}
|
280
|
+
]
|
274
281
|
end
|
275
282
|
|
276
283
|
it 'should invoke callback after model is loaded' do
|
@@ -398,7 +405,7 @@ describe Acfs::Resource::QueryMethods do
|
|
398
405
|
expect(block).not_to receive(:call)
|
399
406
|
|
400
407
|
model.find_by! age: 24, &block
|
401
|
-
expect { Acfs.run }.to raise_error
|
408
|
+
expect { Acfs.run }.to raise_error Acfs::ResourceNotFound
|
402
409
|
end
|
403
410
|
end
|
404
411
|
end
|
@@ -410,25 +417,25 @@ describe Acfs::Resource::QueryMethods do
|
|
410
417
|
.to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
411
418
|
headers: {
|
412
419
|
'X-Total-Pages' => '4',
|
413
|
-
'Link'
|
420
|
+
'Link' => '<http://users.example.org/users?page=2>; rel="next"'
|
414
421
|
})
|
415
422
|
stub_request(:get, 'http://users.example.org/users?page=2')
|
416
423
|
.to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
417
424
|
headers: {
|
418
425
|
'X-Total-Pages' => '4',
|
419
|
-
'Link'
|
426
|
+
'Link' => '<http://users.example.org/users?page=3>; rel="next"'
|
420
427
|
})
|
421
428
|
stub_request(:get, 'http://users.example.org/users?page=3')
|
422
429
|
.to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
423
430
|
headers: {
|
424
431
|
'X-Total-Pages' => '4',
|
425
|
-
'Link'
|
432
|
+
'Link' => '<http://users.example.org/users?page=4>; rel="next"'
|
426
433
|
})
|
427
434
|
stub_request(:get, 'http://users.example.org/users?page=4')
|
428
435
|
.to_return response([{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
429
436
|
headers: {
|
430
437
|
'X-Total-Pages' => '4',
|
431
|
-
'Link'
|
438
|
+
'Link' => ''
|
432
439
|
})
|
433
440
|
end
|
434
441
|
|
@@ -452,25 +459,25 @@ describe Acfs::Resource::QueryMethods do
|
|
452
459
|
.to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
453
460
|
headers: {
|
454
461
|
'X-Total-Pages' => '4',
|
455
|
-
'Link'
|
462
|
+
'Link' => '<http://users.example.org/users?where=fuu&page=2>; rel="next"'
|
456
463
|
})
|
457
464
|
stub_request(:get, 'http://users.example.org/users?where=fuu&page=2')
|
458
465
|
.to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
459
466
|
headers: {
|
460
467
|
'X-Total-Pages' => '4',
|
461
|
-
'Link'
|
468
|
+
'Link' => '<http://users.example.org/users?page=3>; rel="next"'
|
462
469
|
})
|
463
470
|
stub_request(:get, 'http://users.example.org/users?page=3')
|
464
471
|
.to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
465
472
|
headers: {
|
466
473
|
'X-Total-Pages' => '4',
|
467
|
-
'Link'
|
474
|
+
'Link' => '<http://users.example.org/users?page=4>; rel="next"'
|
468
475
|
})
|
469
476
|
stub_request(:get, 'http://users.example.org/users?page=4')
|
470
477
|
.to_return response([{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
471
478
|
headers: {
|
472
479
|
'X-Total-Pages' => '4',
|
473
|
-
'Link'
|
480
|
+
'Link' => ''
|
474
481
|
})
|
475
482
|
end
|
476
483
|
|
@@ -496,25 +503,25 @@ describe Acfs::Resource::QueryMethods do
|
|
496
503
|
.to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
497
504
|
headers: {
|
498
505
|
'X-Total-Pages' => '4',
|
499
|
-
'Link'
|
506
|
+
'Link' => '<http://users.example.org/users?page=2>; rel="next"'
|
500
507
|
})
|
501
508
|
stub_request(:get, 'http://users.example.org/users?page=2')
|
502
509
|
.to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
503
510
|
headers: {
|
504
511
|
'X-Total-Pages' => '4',
|
505
|
-
'Link'
|
512
|
+
'Link' => '<http://users.example.org/users?page=3>; rel="next"'
|
506
513
|
})
|
507
514
|
stub_request(:get, 'http://users.example.org/users?page=3')
|
508
515
|
.to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}, {id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
509
516
|
headers: {
|
510
517
|
'X-Total-Pages' => '4',
|
511
|
-
'Link'
|
518
|
+
'Link' => '<http://users.example.org/users?page=4>; rel="next"'
|
512
519
|
})
|
513
520
|
stub_request(:get, 'http://users.example.org/users?page=4')
|
514
521
|
.to_return response([{id: 5, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
515
522
|
headers: {
|
516
523
|
'X-Total-Pages' => '4',
|
517
|
-
'Link'
|
524
|
+
'Link' => ''
|
518
525
|
})
|
519
526
|
end
|
520
527
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Acfs::Response::Formats do
|
@@ -9,7 +11,7 @@ describe Acfs::Response::Formats do
|
|
9
11
|
let(:response) { Acfs::Response.new request, status: status, headers: headers, body: body }
|
10
12
|
|
11
13
|
context 'without Content-Type header' do
|
12
|
-
let(:headers)
|
14
|
+
let(:headers) { {} }
|
13
15
|
|
14
16
|
it "should fallback on 'text/plain'" do
|
15
17
|
expect(response.content_type).to be == Mime[:text]
|
data/spec/acfs/runner_spec.rb
CHANGED
@@ -1,25 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
class NullAdapter < Acfs::Adapter::Base
|
4
6
|
# Start processing queued requests.
|
5
7
|
#
|
6
|
-
def start
|
7
|
-
end
|
8
|
+
def start; end
|
8
9
|
|
9
10
|
# Abort running and queued requests.
|
10
11
|
#
|
11
|
-
def abort
|
12
|
-
end
|
12
|
+
def abort; end
|
13
13
|
|
14
14
|
# Run request right now skipping queue.
|
15
15
|
#
|
16
|
-
def run(_)
|
17
|
-
end
|
16
|
+
def run(_); end
|
18
17
|
|
19
18
|
# Enqueue request to be run later.
|
20
19
|
#
|
21
|
-
def queue(_)
|
22
|
-
end
|
20
|
+
def queue(_); end
|
23
21
|
end
|
24
22
|
|
25
23
|
class NotificationCollector
|