acfs 1.3.2 → 1.3.3

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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. metadata +8 -141
  3. data/CHANGELOG.md +0 -325
  4. data/LICENSE +0 -22
  5. data/README.md +0 -334
  6. data/acfs.gemspec +0 -37
  7. data/lib/acfs.rb +0 -49
  8. data/lib/acfs/adapter/base.rb +0 -26
  9. data/lib/acfs/adapter/typhoeus.rb +0 -60
  10. data/lib/acfs/collection.rb +0 -27
  11. data/lib/acfs/collections/paginatable.rb +0 -75
  12. data/lib/acfs/configuration.rb +0 -113
  13. data/lib/acfs/errors.rb +0 -106
  14. data/lib/acfs/global.rb +0 -99
  15. data/lib/acfs/location.rb +0 -78
  16. data/lib/acfs/middleware/base.rb +0 -20
  17. data/lib/acfs/middleware/json.rb +0 -27
  18. data/lib/acfs/middleware/logger.rb +0 -23
  19. data/lib/acfs/middleware/msgpack.rb +0 -30
  20. data/lib/acfs/middleware/print.rb +0 -21
  21. data/lib/acfs/middleware/serializer.rb +0 -39
  22. data/lib/acfs/operation.rb +0 -81
  23. data/lib/acfs/request.rb +0 -36
  24. data/lib/acfs/request/callbacks.rb +0 -50
  25. data/lib/acfs/resource.rb +0 -37
  26. data/lib/acfs/resource/attributes.rb +0 -268
  27. data/lib/acfs/resource/attributes/base.rb +0 -28
  28. data/lib/acfs/resource/attributes/boolean.rb +0 -37
  29. data/lib/acfs/resource/attributes/date_time.rb +0 -31
  30. data/lib/acfs/resource/attributes/dict.rb +0 -37
  31. data/lib/acfs/resource/attributes/float.rb +0 -31
  32. data/lib/acfs/resource/attributes/integer.rb +0 -27
  33. data/lib/acfs/resource/attributes/list.rb +0 -34
  34. data/lib/acfs/resource/attributes/string.rb +0 -24
  35. data/lib/acfs/resource/attributes/uuid.rb +0 -47
  36. data/lib/acfs/resource/dirty.rb +0 -35
  37. data/lib/acfs/resource/initialization.rb +0 -29
  38. data/lib/acfs/resource/loadable.rb +0 -33
  39. data/lib/acfs/resource/locatable.rb +0 -128
  40. data/lib/acfs/resource/operational.rb +0 -22
  41. data/lib/acfs/resource/persistence.rb +0 -257
  42. data/lib/acfs/resource/query_methods.rb +0 -264
  43. data/lib/acfs/resource/service.rb +0 -42
  44. data/lib/acfs/resource/validation.rb +0 -37
  45. data/lib/acfs/response.rb +0 -28
  46. data/lib/acfs/response/formats.rb +0 -25
  47. data/lib/acfs/response/status.rb +0 -31
  48. data/lib/acfs/rspec.rb +0 -11
  49. data/lib/acfs/runner.rb +0 -97
  50. data/lib/acfs/service.rb +0 -91
  51. data/lib/acfs/service/middleware.rb +0 -56
  52. data/lib/acfs/service/middleware/stack.rb +0 -63
  53. data/lib/acfs/singleton_resource.rb +0 -83
  54. data/lib/acfs/stub.rb +0 -172
  55. data/lib/acfs/util.rb +0 -20
  56. data/lib/acfs/version.rb +0 -14
  57. data/lib/acfs/yard.rb +0 -5
  58. data/spec/acfs/adapter/typhoeus_spec.rb +0 -28
  59. data/spec/acfs/collection_spec.rb +0 -155
  60. data/spec/acfs/configuration_spec.rb +0 -51
  61. data/spec/acfs/global_spec.rb +0 -137
  62. data/spec/acfs/location_spec.rb +0 -23
  63. data/spec/acfs/middleware/json_spec.rb +0 -63
  64. data/spec/acfs/middleware/msgpack_spec.rb +0 -60
  65. data/spec/acfs/operation_spec.rb +0 -10
  66. data/spec/acfs/request/callbacks_spec.rb +0 -46
  67. data/spec/acfs/request_spec.rb +0 -77
  68. data/spec/acfs/resource/attributes/boolean_spec.rb +0 -56
  69. data/spec/acfs/resource/attributes/date_time_spec.rb +0 -49
  70. data/spec/acfs/resource/attributes/dict_spec.rb +0 -75
  71. data/spec/acfs/resource/attributes/float_spec.rb +0 -59
  72. data/spec/acfs/resource/attributes/integer_spec.rb +0 -34
  73. data/spec/acfs/resource/attributes/list_spec.rb +0 -58
  74. data/spec/acfs/resource/attributes/uuid_spec.rb +0 -40
  75. data/spec/acfs/resource/attributes_spec.rb +0 -179
  76. data/spec/acfs/resource/dirty_spec.rb +0 -47
  77. data/spec/acfs/resource/initialization_spec.rb +0 -30
  78. data/spec/acfs/resource/loadable_spec.rb +0 -20
  79. data/spec/acfs/resource/locatable_spec.rb +0 -116
  80. data/spec/acfs/resource/persistance_spec.rb +0 -316
  81. data/spec/acfs/resource/query_methods_spec.rb +0 -541
  82. data/spec/acfs/resource/validation_spec.rb +0 -127
  83. data/spec/acfs/response/formats_spec.rb +0 -50
  84. data/spec/acfs/response/status_spec.rb +0 -69
  85. data/spec/acfs/runner_spec.rb +0 -97
  86. data/spec/acfs/service/middleware_spec.rb +0 -33
  87. data/spec/acfs/service_spec.rb +0 -46
  88. data/spec/acfs/singleton_resource_spec.rb +0 -15
  89. data/spec/acfs/stub_spec.rb +0 -343
  90. data/spec/acfs_spec.rb +0 -203
  91. data/spec/fixtures/config.yml +0 -14
  92. data/spec/spec_helper.rb +0 -41
  93. data/spec/support/hash.rb +0 -9
  94. data/spec/support/response.rb +0 -10
  95. data/spec/support/service.rb +0 -91
  96. data/spec/support/shared/find_callbacks.rb +0 -48
@@ -1,20 +0,0 @@
1
- module Acfs
2
- module Util
3
- # TODO: Merge wit features in v1.0
4
- module Callbacks
5
- def __callbacks__
6
- @__callbacks__ ||= []
7
- end
8
-
9
- def __invoke__
10
- __callbacks__.each {|c| c.call self }
11
- end
12
- end
13
-
14
- # TODO: Replace delegator with promise or future for the long run.
15
- class ResourceDelegator < SimpleDelegator
16
- delegate :class, :is_a?, :kind_of?, :nil?, to: :__getobj__
17
- include Callbacks
18
- end
19
- end
20
- end
@@ -1,14 +0,0 @@
1
- module Acfs
2
- module VERSION
3
- MAJOR = 1
4
- MINOR = 3
5
- PATCH = 2
6
- STAGE = nil
7
-
8
- STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
9
-
10
- def self.to_s
11
- STRING
12
- end
13
- end
14
- end
@@ -1,5 +0,0 @@
1
- # YARD macros
2
-
3
- # @!macro [new] experimental
4
- # @api experimental
5
- # @note This class or method is *experimental*. It may change without further notice or major version bump.
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Adapter::Typhoeus do
4
- let(:adapter) { described_class.new }
5
- before { WebMock.allow_net_connect! }
6
-
7
- it 'raises an error' do
8
- request1 = Acfs::Request.new 'http://altimos.de/404.1' do |_rsp|
9
- raise '404-1'
10
- end
11
- request2 = Acfs::Request.new 'http://altimos.de/404.2' do |_rsp|
12
- raise '404-2'
13
- end
14
- adapter.queue request1
15
- adapter.queue request2
16
-
17
- expect { adapter.start }.to raise_error(/404\-[12]/)
18
- expect { adapter.start }.to_not raise_error
19
- end
20
-
21
- it 'passes arguments to typhoeus hydra' do
22
- value = {key: 1, key2: 2}
23
-
24
- expect(::Typhoeus::Hydra).to receive(:new).with(value)
25
-
26
- described_class.new(**value).send :hydra
27
- end
28
- end
@@ -1,155 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Collection do
4
- let(:model) { MyUser }
5
-
6
- describe 'Pagination' do
7
- let(:params) { Hash.new }
8
- let!(:collection) { model.all params }
9
-
10
- subject { Acfs.run; collection }
11
-
12
- context 'without explicit page parameter' do
13
- before do
14
- stub_request(:get, 'http://users.example.org/users')
15
- .to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
16
- headers: {
17
- 'X-Total-Pages' => '2',
18
- 'X-Total-Count' => '10'
19
- })
20
- end
21
-
22
- its(:total_pages) { should eq 2 }
23
- its(:current_page) { should eq 1 }
24
- its(:total_count) { should eq 10 }
25
- end
26
-
27
- context 'with page parameter' do
28
- let(:params) { {page: 2} }
29
- before do
30
- stub_request(:get, 'http://users.example.org/users?page=2')
31
- .to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
32
- headers: {
33
- 'X-Total-Pages' => '2',
34
- 'X-Total-Count' => '10'
35
- })
36
- end
37
-
38
- its(:total_pages) { should eq 2 }
39
- its(:current_page) { should eq 2 }
40
- its(:total_count) { should eq 10 }
41
- end
42
-
43
- context 'with non-numerical page parameter' do
44
- let(:params) { {page: 'e546f5'} }
45
- before do
46
- stub_request(:get, 'http://users.example.org/users?page=e546f5')
47
- .to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
48
- headers: {
49
- 'X-Total-Pages' => '2',
50
- 'X-Total-Count' => '10'
51
- })
52
- end
53
-
54
- its(:total_pages) { should eq 2 }
55
- its(:current_page) { should eq 'e546f5' }
56
- its(:total_count) { should eq 10 }
57
- end
58
-
59
- describe '#next_page' do
60
- before do
61
- stub_request(:get, 'http://users.example.org/users')
62
- .to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
63
- headers: {
64
- 'X-Total-Pages' => '2',
65
- 'Link' => '<http://users.example.org/users?page=2>; rel="next"'
66
- })
67
- end
68
- let!(:req) do
69
- stub_request(:get, 'http://users.example.org/users?page=2').to_return response([])
70
- end
71
- let!(:collection) { model.all }
72
- subject { Acfs.run; collection.next_page }
73
-
74
- it { should be_a Acfs::Collection }
75
-
76
- it 'should have fetched page 2' do
77
- subject
78
- Acfs.run
79
- expect(req).to have_been_requested
80
- end
81
- end
82
-
83
- describe '#prev_page' do
84
- before do
85
- stub_request(:get, 'http://users.example.org/users?page=2')
86
- .to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
87
- headers: {
88
- 'X-Total-Pages' => '2',
89
- 'Link' => '<http://users.example.org/users>; rel="prev"'
90
- })
91
- end
92
- let!(:req) do
93
- stub_request(:get, 'http://users.example.org/users').to_return response([])
94
- end
95
- let!(:collection) { model.all page: 2 }
96
- subject { Acfs.run; collection.prev_page }
97
-
98
- it { should be_a Acfs::Collection }
99
-
100
- it 'should have fetched page 1' do
101
- subject
102
- Acfs.run
103
- expect(req).to have_been_requested
104
- end
105
- end
106
-
107
- describe '#first_page' do
108
- before do
109
- stub_request(:get, 'http://users.example.org/users?page=2')
110
- .to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
111
- headers: {
112
- 'X-Total-Pages' => '2',
113
- 'Link' => '<http://users.example.org/users>; rel="first"'
114
- })
115
- end
116
- let!(:req) do
117
- stub_request(:get, 'http://users.example.org/users').to_return response([])
118
- end
119
- let!(:collection) { model.all page: 2 }
120
- subject { Acfs.run; collection.first_page }
121
-
122
- it { should be_a Acfs::Collection }
123
-
124
- it 'should have fetched page 1' do
125
- subject
126
- Acfs.run
127
- expect(req).to have_been_requested
128
- end
129
- end
130
-
131
- describe '#last_page' do
132
- before do
133
- stub_request(:get, 'http://users.example.org/users?page=2')
134
- .to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
135
- headers: {
136
- 'X-Total-Pages' => '2',
137
- 'Link' => '<http://users.example.org/users?page=12>; rel="last"'
138
- })
139
- end
140
- let!(:req) do
141
- stub_request(:get, 'http://users.example.org/users?page=12').to_return response([])
142
- end
143
- let!(:collection) { model.all page: 2 }
144
- subject { Acfs.run; collection.last_page }
145
-
146
- it { should be_a Acfs::Collection }
147
-
148
- it 'should have fetched page 1' do
149
- subject
150
- Acfs.run
151
- expect(req).to have_been_requested
152
- end
153
- end
154
- end
155
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Configuration do
4
- let(:cfg) { Acfs::Configuration.new }
5
- before { @configuration = Acfs::Configuration.current.dup }
6
- after { Acfs::Configuration.set @configuration }
7
-
8
- describe 'Acfs.configure' do
9
- it 'should invoke configure on current configuration' do
10
- expect(Acfs::Configuration.current).to receive(:configure).once.and_call_original
11
-
12
- Acfs.configure do |c|
13
- expect(c).to be_a Acfs::Configuration
14
- end
15
- end
16
- end
17
-
18
- describe '.load' do
19
- it 'should be able to load YAML' do
20
- cfg.configure do
21
- load 'spec/fixtures/config.yml'
22
- end
23
-
24
- expect(cfg.locate(UserService).to_s).to be == 'http://localhost:3001/'
25
- expect(cfg.locate(CommentService).to_s).to be == 'http://localhost:3002/'
26
- end
27
-
28
- context 'with RACK_ENV' do
29
- before { @env = ENV['RACK_ENV']; ENV['RACK_ENV'] = 'production' }
30
- after { ENV['RACK_ENV'] = @env }
31
-
32
- it 'should load ENV block' do
33
- cfg.configure do
34
- load 'spec/fixtures/config.yml'
35
- end
36
-
37
- expect(cfg.locate(UserService).to_s).to be == 'http://user.example.org/'
38
- expect(cfg.locate(CommentService).to_s).to be == 'http://comment.example.org/'
39
- end
40
- end
41
- end
42
-
43
- describe '#adapter' do
44
- let(:object) { Object.new }
45
-
46
- it 'should be a accessor' do
47
- cfg.adapter = object
48
- expect(cfg.adapter).to eq object
49
- end
50
- end
51
- end
@@ -1,137 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class NotificationCollector
4
- def call(*args)
5
- events << ActiveSupport::Notifications::Event.new(*args)
6
- end
7
-
8
- def events
9
- @events ||= []
10
- end
11
- end
12
-
13
- describe ::Acfs::Global do
14
- let(:adapter) { ::NullAdapter.new }
15
- let(:runner) { double 'runner' }
16
- let(:collector) { NotificationCollector.new }
17
- let(:acfs) { Object.new.tap {|o| o.extend ::Acfs::Global } }
18
-
19
- describe 'instrumentation' do
20
- before do
21
- # allow(runner).to receive(:start)
22
- allow(acfs).to receive(:runner).and_return runner
23
- end
24
-
25
- describe '#run' do
26
- before do
27
- ::ActiveSupport::Notifications.subscribe 'acfs.run', collector
28
- end
29
- it 'should trigger event' do
30
- Acfs.run
31
- expect(collector.events).to have(1).items
32
- end
33
- end
34
-
35
- describe '#reset' do
36
- before do
37
- ::ActiveSupport::Notifications.subscribe 'acfs.reset', collector
38
- end
39
- it 'should trigger event' do
40
- Acfs.reset
41
- expect(collector.events).to have(1).items
42
- end
43
- end
44
- end
45
-
46
- describe '#on' do
47
- before do
48
- stub_request(:get, %r{http://users.example.org/users/\d+}).to_return(
49
- status: 200,
50
- body: '{}',
51
- headers: {'Content-Type' => 'application/json'})
52
- end
53
-
54
- it 'should invoke when both resources' do
55
- user1 = MyUser.find 1
56
- user2 = MyUser.find 2
57
-
58
- expect do |cb|
59
- Acfs.on(user1, user2, &cb)
60
- Acfs.run
61
- end.to yield_with_args(user1, user2)
62
- end
63
-
64
- it 'should invoke when both resources when loaded' do
65
- user1 = MyUser.find 1
66
- user2 = MyUser.find 2
67
-
68
- Acfs.on(user1, user2) do |u1, u2|
69
- expect(u1).to be_loaded
70
- expect(u2).to be_loaded
71
- end
72
- Acfs.run
73
- end
74
-
75
- context 'with an empty result for a find_by call' do
76
- before do
77
- stub_request(:get, %r{http://users.example.org/users})
78
- .with(query: {id: '2'})
79
- .to_return(
80
- status: 200,
81
- body: '{}',
82
- headers: {'Content-Type' => 'application/json'}
83
- )
84
- end
85
-
86
- it 'invokes once both requests are finished' do
87
- user1 = MyUser.find 1
88
- user2 = MyUser.find_by id: 2
89
-
90
- expect do |cb|
91
- Acfs.on(user1, user2, &cb)
92
- Acfs.run
93
- end.to yield_with_args(user1, be_nil)
94
- end
95
-
96
- it 'invokes once remaining requests are finished' do
97
- user1 = MyUser.find 1
98
- Acfs.run # Finish the first request
99
-
100
- user2 = MyUser.find_by id: 2
101
-
102
- expect do |cb|
103
- Acfs.on(user1, user2, &cb)
104
- Acfs.run
105
- end.to yield_with_args(user1, be_nil)
106
- end
107
-
108
- it 'invokes immediately when all requests have already been finished' do
109
- user1 = MyUser.find 1
110
- user2 = MyUser.find_by id: 2
111
- Acfs.run
112
-
113
- expect do |cb|
114
- Acfs.on(user1, user2, &cb)
115
- end.to yield_with_args(user1, be_nil)
116
- end
117
- end
118
- end
119
-
120
- describe '#runner' do
121
- it 'returns per-thread runner' do
122
- runner1 = Thread.new { acfs.runner } .value
123
- runner2 = Thread.new { acfs.runner } .value
124
-
125
- expect(runner1).to_not equal runner2
126
- end
127
-
128
- it 'uses configurated adapter' do
129
- adapter = double :adapter
130
- expect(Acfs::Configuration.current).to receive(:adapter).and_return(-> { adapter })
131
-
132
- runner = Thread.new { acfs.runner }.value
133
-
134
- expect(runner.adapter).to equal adapter
135
- end
136
- end
137
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ::Acfs::Location do
4
- let(:location) { described_class.new(uri, args) }
5
- let(:uri) { 'http://localhost/users/:id' }
6
- let(:args) { {id: 4} }
7
-
8
- describe '#str' do
9
- subject(:str) { location.str }
10
-
11
- it 'replaces variables with values' do
12
- expect(str).to eq 'http://localhost/users/4'
13
- end
14
-
15
- context 'with special characters' do
16
- let(:args) { {id: '4 [@(\/!^$'} }
17
-
18
- it 'escapes special characters' do
19
- expect(str).to eq 'http://localhost/users/4+%5B%40%28%5C%2F%21%5E%24'
20
- end
21
- end
22
- end
23
- end
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Middleware::JSON 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', method: 'GET', data: data }
8
- let(:response) { Acfs::Response.new request, status: 200, headers: headers, body: body }
9
- let(:decoder) { Acfs::Middleware::JSON.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/json'
19
- end
20
-
21
- it 'should append Accept header' do
22
- expect(request.headers['Accept']).to eq 'application/json;q=1'
23
- end
24
-
25
- it 'should serialize data to JSON' do
26
- expect(JSON.parse(request.body)).to eq data.map(&:stringify_keys)
27
- end
28
- end
29
- end
30
-
31
- describe 'decode' do
32
- context 'with JSON response' do
33
- let(:headers) { {'Content-Type' => 'application/json; charset=utf-8'} }
34
- let(:body) { data.to_json }
35
-
36
- it 'should decode body data' do
37
- request.complete! response
38
-
39
- expect(response.data).to be == data.map(&:stringify_keys)
40
- end
41
- end
42
-
43
- context 'with invalid JSON response' do
44
- let(:headers) { {'Content-Type' => 'application/json'} }
45
- let(:body) { data.to_json[4..-4] }
46
-
47
- it 'should raise an error' do
48
- expect { request.complete! response }.to raise_error(MultiJson::LoadError)
49
- end
50
- end
51
-
52
- context 'without JSON response' do
53
- let(:headers) { {'Content-Type' => 'application/text'} }
54
- let(:body) { data.to_json }
55
-
56
- it 'should not decode non-JSON encoded responses' do
57
- request.complete! response
58
-
59
- expect(response.data).to be_nil
60
- end
61
- end
62
- end
63
- end