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
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Middleware::MessagePack do
4
- let(:data) { [{id: 1, name: 'Anon'}, {id: 2, name: 'John', friends: [1]}] }
5
- let(:body) { '' }
6
- let(:headers) { {} }
7
- let(:request) { Acfs::Request.new 'url', data: data }
8
- let(:response) { Acfs::Response.new request, status: 200, headers: headers, body: body }
9
- let(:decoder) { Acfs::Middleware::MessagePack.new ->(req) { req } }
10
-
11
- before do
12
- decoder.call request
13
- end
14
-
15
- describe 'encode' do
16
- context 'with not serialized request' do
17
- it 'should set Content-Type' do
18
- expect(request.headers['Content-Type']).to eq 'application/x-msgpack'
19
- end
20
-
21
- it 'should append Accept header' do
22
- expect(request.headers['Accept']).to eq 'application/x-msgpack;q=1'
23
- end
24
-
25
- context 'with JSON chained' do
26
- let(:decoder) { Acfs::Middleware::JSON.new super(), q: 0.5 }
27
-
28
- it 'should append to Accept header' do
29
- expect(request.headers['Accept']).to eq 'application/json;q=0.5,application/x-msgpack;q=1'
30
- end
31
- end
32
-
33
- it 'should serialize data to MessagePack' do
34
- expect(MessagePack.unpack(request.body)).to eq data.map(&:stringify_keys)
35
- end
36
- end
37
- end
38
-
39
- context 'with Message Pack response' do
40
- let(:headers) { {'Content-Type' => 'application/x-msgpack'} }
41
- let(:body) { MessagePack.pack data }
42
-
43
- it 'should decode body data' do
44
- request.complete! response
45
-
46
- expect(response.data).to be == data.map(&:stringify_keys)
47
- end
48
- end
49
-
50
- context 'without Message Pack response' do
51
- let(:headers) { {'Content-Type' => 'application/text'} }
52
- let(:body) { data.to_json }
53
-
54
- it 'should not decode non-MessagePack encoded responses' do
55
- request.complete! response
56
-
57
- expect(response.data).to be_nil
58
- end
59
- end
60
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ::Acfs::Operation do
4
- let(:operation) { described_class.new MyUser, :read, params: {id: 0} }
5
-
6
- context '#request' do
7
- subject { operation.request }
8
- its(:operation) { should eq operation }
9
- end
10
- end
@@ -1,75 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Resource::Attributes::Dict do
4
- let(:type) { Acfs::Resource::Attributes::Dict.new }
5
-
6
- describe '#cast' do
7
- subject { -> { type.cast value } }
8
-
9
- context 'with nil' do
10
- let(:value) { nil }
11
- it { expect(subject.call).to eq nil }
12
- end
13
-
14
- context 'with blank string (I)' do
15
- let(:value) { '' }
16
- it { expect(subject.call).to eq Hash.new }
17
- end
18
-
19
- context 'with blank string (II)' do
20
- let(:value) { " \t" }
21
- it { expect(subject.call).to eq Hash.new }
22
- end
23
-
24
- context 'with hash' do
25
- let(:value) { {3 => true, abc: 4} }
26
- it { expect(subject.call).to eq value }
27
- end
28
-
29
- context 'with non hashable object' do
30
- let(:value) { Object.new }
31
- it { is_expected.to raise_error TypeError }
32
- end
33
-
34
- context 'with hashable object (I)' do
35
- let(:value) do
36
- Class.new do
37
- def to_hash
38
- {id: object_id}
39
- end
40
- end.new
41
- end
42
-
43
- it { expect(subject.call).to eq id: value.object_id }
44
- end
45
-
46
- context 'with hashable object (II)' do
47
- let(:value) do
48
- Class.new do
49
- def to_h
50
- {id: object_id}
51
- end
52
- end.new
53
- end
54
-
55
- it { expect(subject.call).to eq id: value.object_id }
56
- end
57
-
58
- context 'with serializable object' do
59
- let(:value) do
60
- Class.new do
61
- def serializable_hash
62
- {id: object_id}
63
- end
64
- end.new
65
- end
66
-
67
- it { expect(subject.call).to eq id: value.object_id }
68
- end
69
-
70
- context 'with hash subclass object' do
71
- let(:value) { HashWithIndifferentAccess.new test: :foo }
72
- it { expect(subject.call).to be value }
73
- end
74
- end
75
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Resource::Attributes::Integer do
4
- let(:type) { Acfs::Resource::Attributes::Integer.new }
5
-
6
- describe '#cast' do
7
- subject { -> { type.cast value } }
8
-
9
- context 'with nil' do
10
- let(:value) { nil }
11
- it { expect(subject.call).to eq nil }
12
- end
13
-
14
- context 'with empty string' do
15
- let(:value) { '' }
16
- it { expect(subject.call).to eq 0 }
17
- end
18
-
19
- context 'with blank string' do
20
- let(:value) { " \t" }
21
- it { expect(subject.call).to eq 0 }
22
- end
23
-
24
- context 'with string' do
25
- let(:value) { '123' }
26
- it { expect(subject.call).to eq 123 }
27
- end
28
-
29
- context 'with invalid string' do
30
- let(:value) { '123a' }
31
- it { is_expected.to raise_error ArgumentError }
32
- end
33
- end
34
- end