acfs 1.6.0 → 1.7.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 +1 -0
- data/README.md +16 -19
- data/acfs.gemspec +2 -0
- data/lib/acfs/adapter/typhoeus.rb +6 -4
- data/lib/acfs/configuration.rb +13 -3
- data/lib/acfs/errors.rb +1 -1
- data/lib/acfs/global.rb +2 -2
- data/lib/acfs/location.rb +1 -1
- data/lib/acfs/operation.rb +1 -1
- data/lib/acfs/request/callbacks.rb +1 -1
- data/lib/acfs/request.rb +1 -1
- data/lib/acfs/resource/attributes/uuid.rb +1 -1
- data/lib/acfs/resource/locatable.rb +2 -2
- data/lib/acfs/resource/query_methods.rb +2 -2
- data/lib/acfs/runner.rb +15 -15
- data/lib/acfs/stub.rb +34 -29
- data/lib/acfs/version.rb +2 -2
- data/spec/acfs/adapter/typhoeus_spec.rb +1 -1
- data/spec/acfs/collection_spec.rb +66 -41
- data/spec/acfs/configuration_spec.rb +22 -12
- data/spec/acfs/global_spec.rb +9 -7
- data/spec/acfs/middleware/json_spec.rb +8 -8
- data/spec/acfs/middleware/{msgpack_spec.rb → message_pack_spec.rb} +6 -6
- data/spec/acfs/operation_spec.rb +3 -2
- data/spec/acfs/request/callbacks_spec.rb +19 -10
- data/spec/acfs/request_spec.rb +15 -19
- data/spec/acfs/resource/attributes/boolean_spec.rb +32 -32
- data/spec/acfs/resource/attributes/date_time_spec.rb +16 -8
- data/spec/acfs/resource/attributes/dict_spec.rb +15 -9
- data/spec/acfs/resource/attributes/float_spec.rb +20 -10
- data/spec/acfs/resource/attributes/integer_spec.rb +10 -5
- data/spec/acfs/resource/attributes/list_spec.rb +13 -8
- data/spec/acfs/resource/attributes/uuid_spec.rb +12 -6
- data/spec/acfs/resource/attributes_spec.rb +33 -32
- data/spec/acfs/resource/dirty_spec.rb +6 -3
- data/spec/acfs/resource/initialization_spec.rb +4 -5
- data/spec/acfs/resource/loadable_spec.rb +3 -1
- data/spec/acfs/resource/locatable_spec.rb +24 -18
- data/spec/acfs/resource/{persistance_spec.rb → persistence_spec.rb} +114 -82
- data/spec/acfs/resource/query_methods_spec.rb +143 -110
- data/spec/acfs/resource/validation_spec.rb +34 -27
- data/spec/acfs/response/formats_spec.rb +8 -8
- data/spec/acfs/response/status_spec.rb +16 -9
- data/spec/acfs/runner_spec.rb +10 -8
- data/spec/acfs/service/middleware_spec.rb +3 -3
- data/spec/acfs/service_spec.rb +5 -4
- data/spec/acfs/singleton_resource_spec.rb +2 -1
- data/spec/acfs/stub_spec.rb +57 -53
- data/spec/acfs_spec.rb +111 -93
- data/spec/spec_helper.rb +1 -1
- data/spec/support/response.rb +2 -2
- data/spec/support/service.rb +1 -1
- data/spec/support/shared/find_callbacks.rb +14 -10
- metadata +9 -8
data/spec/acfs_spec.rb
CHANGED
@@ -4,57 +4,68 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe 'Acfs' do
|
6
6
|
before do
|
7
|
-
stub_request(:get, 'http://users.example.org/users')
|
8
|
-
|
9
|
-
|
10
|
-
stub_request(:get, 'http://users.example.org/users/
|
11
|
-
|
12
|
-
|
7
|
+
stub_request(:get, 'http://users.example.org/users')
|
8
|
+
.to_return response([{id: 1, name: 'Anon', age: 12}, {id: 2, name: 'John', age: 26}])
|
9
|
+
|
10
|
+
stub_request(:get, 'http://users.example.org/users/2')
|
11
|
+
.to_return response(id: 2, name: 'John', age: 26)
|
12
|
+
|
13
|
+
stub_request(:get, 'http://users.example.org/users/3')
|
14
|
+
.to_return response(id: 3, name: 'Miraculix', age: 122)
|
15
|
+
|
16
|
+
stub_request(:get, 'http://users.example.org/users/100')
|
17
|
+
.to_return response(id: 100, name: 'Jimmy', age: 45)
|
18
|
+
|
19
|
+
stub_request(:get, 'http://users.example.org/users/2/friends')
|
20
|
+
.to_return response([{id: 1, name: 'Anon', age: 12}])
|
21
|
+
|
22
|
+
stub_request(:get, 'http://comments.example.org/comments?user=2')
|
23
|
+
.to_return response([{id: 1, text: 'Comment #1'}, {id: 2, text: 'Comment #2'}])
|
13
24
|
end
|
14
25
|
|
15
|
-
it '
|
26
|
+
it 'updates single resource synchronously' do
|
16
27
|
stub = stub_request(:put, 'http://users.example.org/users/2')
|
17
|
-
|
28
|
+
.to_return {|request| {body: request.body, headers: {'Content-Type' => request.headers['Content-Type']}} }
|
18
29
|
|
19
|
-
|
30
|
+
user = MyUser.find 2
|
20
31
|
Acfs.run
|
21
32
|
|
22
|
-
expect(
|
23
|
-
expect(
|
33
|
+
expect(user).not_to be_changed
|
34
|
+
expect(user).to be_persisted
|
24
35
|
|
25
|
-
|
36
|
+
user.name = 'Johnny'
|
26
37
|
|
27
|
-
expect(
|
28
|
-
expect(
|
38
|
+
expect(user).to be_changed
|
39
|
+
expect(user).to be_persisted
|
29
40
|
|
30
|
-
|
41
|
+
user.save
|
31
42
|
|
32
43
|
expect(stub).to have_been_requested
|
33
|
-
expect(
|
34
|
-
expect(
|
44
|
+
expect(user).not_to be_changed
|
45
|
+
expect(user).to be_persisted
|
35
46
|
end
|
36
47
|
|
37
|
-
it '
|
48
|
+
it 'creates a single resource synchronously' do
|
38
49
|
stub = stub_request(:post, 'http://users.example.org/sessions').to_return response(id: 'sessionhash', user: 1)
|
39
50
|
|
40
51
|
session = Session.create ident: 'Anon'
|
41
52
|
|
42
53
|
expect(stub).to have_been_requested
|
43
|
-
expect(session.id).to
|
44
|
-
expect(session.user).to
|
54
|
+
expect(session.id).to eq 'sessionhash'
|
55
|
+
expect(session.user).to eq 1
|
45
56
|
end
|
46
57
|
|
47
|
-
it '
|
48
|
-
|
58
|
+
it 'loads single resource' do
|
59
|
+
user = MyUser.find(2)
|
49
60
|
|
50
|
-
expect(
|
61
|
+
expect(user).not_to be_loaded
|
51
62
|
|
52
63
|
Acfs.run
|
53
64
|
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
-
expect(
|
57
|
-
expect(
|
65
|
+
expect(user).to be_loaded
|
66
|
+
expect(user.id).to eq 2
|
67
|
+
expect(user.name).to eq 'John'
|
68
|
+
expect(user.age).to eq 26
|
58
69
|
end
|
59
70
|
|
60
71
|
describe 'singleton' do
|
@@ -62,144 +73,151 @@ describe 'Acfs' do
|
|
62
73
|
stub_request(:get, 'http://users.example.org/singles?user_id=5').to_return response(score: 250, user_id: 5)
|
63
74
|
end
|
64
75
|
|
65
|
-
it '
|
76
|
+
it 'creates a singleton resource' do
|
66
77
|
stub = stub_request(:post, 'http://users.example.org/singles').to_return response(score: 250, user_id: 5)
|
67
78
|
|
68
|
-
|
69
|
-
expect(
|
79
|
+
single = Single.new user_id: 5, score: 250
|
80
|
+
expect(single.new?).to eq true
|
70
81
|
|
71
|
-
|
82
|
+
single.save
|
72
83
|
expect(stub).to have_been_requested
|
73
84
|
|
74
|
-
expect(
|
75
|
-
expect(
|
76
|
-
expect(
|
85
|
+
expect(single.new?).to eq false
|
86
|
+
expect(single.user_id).to eq 5
|
87
|
+
expect(single.score).to eq 250
|
77
88
|
end
|
78
89
|
|
79
|
-
it '
|
80
|
-
|
90
|
+
it 'loads singleton resource' do
|
91
|
+
single = Single.find user_id: 5
|
81
92
|
Acfs.run
|
82
93
|
|
83
|
-
expect(
|
94
|
+
expect(single.score).to eq 250
|
84
95
|
end
|
85
96
|
|
86
|
-
it '
|
97
|
+
it 'updates singleton resource' do
|
87
98
|
stub = stub_request(:put, 'http://users.example.org/singles').to_return do |request|
|
88
99
|
{
|
89
100
|
body: request.body,
|
90
|
-
headers: {'Content-Type' => request.headers['Content-Type']}
|
101
|
+
headers: {'Content-Type' => request.headers['Content-Type']},
|
91
102
|
}
|
92
103
|
end
|
93
104
|
|
94
|
-
|
105
|
+
single = Single.find user_id: 5
|
95
106
|
Acfs.run
|
96
107
|
|
97
|
-
expect(
|
108
|
+
expect(single.score).to eq 250
|
98
109
|
|
99
|
-
|
100
|
-
|
110
|
+
single.score = 300
|
111
|
+
single.save
|
101
112
|
|
102
113
|
expect(stub).to have_been_requested
|
103
114
|
|
104
|
-
expect(
|
115
|
+
expect(single.score).to eq 300
|
105
116
|
end
|
106
117
|
|
107
|
-
it '
|
118
|
+
it 'deletes singleton resource' do
|
108
119
|
stub = stub_request(:delete, 'http://users.example.org/singles').to_return do |request|
|
109
120
|
{
|
110
121
|
body: request.body,
|
111
|
-
headers: {'Content-Type' => request.headers['Content-Type']}
|
122
|
+
headers: {'Content-Type' => request.headers['Content-Type']},
|
112
123
|
}
|
113
124
|
end
|
114
125
|
|
115
|
-
|
126
|
+
single = Single.find user_id: 5
|
116
127
|
Acfs.run
|
117
128
|
|
118
|
-
expect(
|
129
|
+
expect(single.new?).to eq false
|
119
130
|
|
120
|
-
|
131
|
+
single.delete
|
121
132
|
|
122
133
|
expect(stub).to have_been_requested
|
123
134
|
end
|
124
135
|
|
125
|
-
it '
|
136
|
+
it 'raises error when calling .all' do
|
126
137
|
expect { Single.all }.to raise_error ::Acfs::UnsupportedOperation
|
127
138
|
end
|
128
139
|
end
|
129
140
|
|
130
|
-
it '
|
131
|
-
|
141
|
+
it 'loads multiple single resources' do
|
142
|
+
john = nil
|
143
|
+
mirx = nil
|
144
|
+
jimy = nil
|
145
|
+
|
146
|
+
users = MyUser.find([2, 3, 100]) do |users|
|
132
147
|
# This block should be called only after *all* resources are loaded.
|
133
|
-
|
134
|
-
|
135
|
-
|
148
|
+
john = users[0]
|
149
|
+
mirx = users[1]
|
150
|
+
jimy = users[2]
|
136
151
|
end
|
137
152
|
|
138
|
-
expect(
|
153
|
+
expect(users).not_to be_loaded
|
139
154
|
|
140
155
|
Acfs.run
|
141
156
|
|
142
|
-
expect(
|
143
|
-
expect(
|
157
|
+
expect(users).to be_loaded
|
158
|
+
expect(users).to have(3).items
|
144
159
|
|
145
|
-
expect(
|
146
|
-
expect(
|
147
|
-
expect(
|
148
|
-
expect(
|
160
|
+
expect(users[0].id).to eq 2
|
161
|
+
expect(users[0].name).to eq 'John'
|
162
|
+
expect(users[0].age).to eq 26
|
163
|
+
expect(users[0]).to eq john
|
149
164
|
|
150
|
-
expect(
|
151
|
-
expect(
|
152
|
-
expect(
|
153
|
-
expect(
|
165
|
+
expect(users[1].id).to eq 3
|
166
|
+
expect(users[1].name).to eq 'Miraculix'
|
167
|
+
expect(users[1].age).to eq 122
|
168
|
+
expect(users[1]).to eq mirx
|
154
169
|
|
155
|
-
expect(
|
156
|
-
expect(
|
157
|
-
expect(
|
158
|
-
expect(
|
170
|
+
expect(users[2].id).to eq 100
|
171
|
+
expect(users[2].name).to eq 'Jimmy'
|
172
|
+
expect(users[2].age).to eq 45
|
173
|
+
expect(users[2]).to eq jimy
|
159
174
|
end
|
160
175
|
|
161
|
-
it '
|
162
|
-
|
176
|
+
it 'loads multiple resources' do
|
177
|
+
users = MyUser.all
|
163
178
|
|
164
|
-
expect(
|
179
|
+
expect(users).not_to be_loaded
|
165
180
|
|
166
181
|
Acfs.run
|
167
182
|
|
168
|
-
expect(
|
169
|
-
expect(
|
170
|
-
expect(
|
171
|
-
expect(
|
172
|
-
expect(
|
173
|
-
expect(
|
183
|
+
expect(users).to be_loaded
|
184
|
+
expect(users).to have(2).items
|
185
|
+
expect(users[0].name).to eq 'Anon'
|
186
|
+
expect(users[0].age).to eq 12
|
187
|
+
expect(users[1].name).to eq 'John'
|
188
|
+
expect(users[1].age).to eq 26
|
174
189
|
end
|
175
190
|
|
176
|
-
it '
|
191
|
+
it 'loads associated resources' do
|
177
192
|
pending 'TODO: Implement high level feature'
|
193
|
+
friends = nil
|
178
194
|
|
179
|
-
|
180
|
-
|
195
|
+
user = MyUser.find(2) do |user|
|
196
|
+
friends = user.friends.all
|
181
197
|
end
|
182
198
|
|
183
199
|
Acfs.run
|
184
200
|
|
185
|
-
expect(
|
186
|
-
expect(
|
201
|
+
expect(user.name).to eq 'John'
|
202
|
+
expect(user.age).to eq 26
|
187
203
|
|
188
|
-
expect(
|
204
|
+
expect(friends).to have(1).items
|
189
205
|
end
|
190
206
|
|
191
|
-
it '
|
192
|
-
|
193
|
-
|
194
|
-
|
207
|
+
it 'loads associated resources from different service' do
|
208
|
+
comments = nil
|
209
|
+
|
210
|
+
user = MyUser.find 2 do |user|
|
211
|
+
expect(user.id).to eq 2
|
212
|
+
comments = Comment.where({user: user.id})
|
195
213
|
end
|
196
214
|
|
197
215
|
Acfs.run
|
198
216
|
|
199
|
-
expect(
|
200
|
-
expect(
|
201
|
-
expect(
|
217
|
+
expect(user.id).to eq 2
|
218
|
+
expect(user.name).to eq 'John'
|
219
|
+
expect(user.age).to eq 26
|
202
220
|
|
203
|
-
expect(
|
221
|
+
expect(comments).to have(2).items
|
204
222
|
end
|
205
223
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/response.rb
CHANGED
@@ -4,9 +4,9 @@ require 'json'
|
|
4
4
|
|
5
5
|
def response(data = nil, opts = {})
|
6
6
|
if data
|
7
|
-
opts
|
7
|
+
opts[:body] = JSON.dump(data)
|
8
8
|
opts[:headers] ||= {}
|
9
|
-
opts[:headers]
|
9
|
+
opts[:headers]['Content-Type'] = 'application/json'
|
10
10
|
end
|
11
11
|
opts
|
12
12
|
end
|
data/spec/support/service.rb
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
shared_examples 'a query method with multi-callback support' do
|
4
4
|
let(:cb) { Proc.new }
|
5
5
|
|
6
|
-
it '
|
6
|
+
it 'invokes callback' do
|
7
7
|
expect do |cb|
|
8
8
|
action.call cb
|
9
9
|
Acfs.run
|
10
10
|
end.to yield_with_args
|
11
11
|
end
|
12
12
|
|
13
|
-
it '
|
13
|
+
it 'invokes multiple callbacks' do
|
14
14
|
expect do |cb|
|
15
15
|
object = action.call cb
|
16
16
|
Acfs.add_callback object, &cb
|
@@ -19,31 +19,35 @@ shared_examples 'a query method with multi-callback support' do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe 'callback' do
|
22
|
-
it '
|
22
|
+
it 'is invoked with resource' do
|
23
23
|
proc = proc {}
|
24
|
+
object = nil
|
25
|
+
|
24
26
|
expect(proc).to receive(:call) do |res|
|
25
|
-
expect(res).to equal
|
27
|
+
expect(res).to equal object
|
26
28
|
expect(res).to be_loaded
|
27
29
|
end
|
28
30
|
|
29
|
-
|
31
|
+
object = action.call proc
|
30
32
|
Acfs.run
|
31
33
|
end
|
32
34
|
|
33
|
-
it '
|
35
|
+
it 'invokes multiple callback with loaded resource' do
|
34
36
|
proc1 = proc {}
|
35
37
|
proc2 = proc {}
|
38
|
+
object = nil
|
39
|
+
|
36
40
|
expect(proc1).to receive(:call) do |user|
|
37
|
-
expect(user).to equal
|
41
|
+
expect(user).to equal object
|
38
42
|
expect(user).to be_loaded
|
39
43
|
end
|
40
44
|
expect(proc2).to receive(:call) do |user|
|
41
|
-
expect(user).to equal
|
45
|
+
expect(user).to equal object
|
42
46
|
expect(user).to be_loaded
|
43
47
|
end
|
44
48
|
|
45
|
-
|
46
|
-
Acfs.add_callback(
|
49
|
+
object = action.call proc1
|
50
|
+
Acfs.add_callback(object, &proc2)
|
47
51
|
Acfs.run
|
48
52
|
end
|
49
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -176,7 +176,7 @@ files:
|
|
176
176
|
- spec/acfs/global_spec.rb
|
177
177
|
- spec/acfs/location_spec.rb
|
178
178
|
- spec/acfs/middleware/json_spec.rb
|
179
|
-
- spec/acfs/middleware/
|
179
|
+
- spec/acfs/middleware/message_pack_spec.rb
|
180
180
|
- spec/acfs/operation_spec.rb
|
181
181
|
- spec/acfs/request/callbacks_spec.rb
|
182
182
|
- spec/acfs/request_spec.rb
|
@@ -192,7 +192,7 @@ files:
|
|
192
192
|
- spec/acfs/resource/initialization_spec.rb
|
193
193
|
- spec/acfs/resource/loadable_spec.rb
|
194
194
|
- spec/acfs/resource/locatable_spec.rb
|
195
|
-
- spec/acfs/resource/
|
195
|
+
- spec/acfs/resource/persistence_spec.rb
|
196
196
|
- spec/acfs/resource/query_methods_spec.rb
|
197
197
|
- spec/acfs/resource/validation_spec.rb
|
198
198
|
- spec/acfs/response/formats_spec.rb
|
@@ -212,7 +212,8 @@ files:
|
|
212
212
|
homepage: https://github.com/jgraichen/acfs
|
213
213
|
licenses:
|
214
214
|
- MIT
|
215
|
-
metadata:
|
215
|
+
metadata:
|
216
|
+
rubygems_mfa_required: 'true'
|
216
217
|
post_install_message:
|
217
218
|
rdoc_options: []
|
218
219
|
require_paths:
|
@@ -228,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
229
|
- !ruby/object:Gem::Version
|
229
230
|
version: '0'
|
230
231
|
requirements: []
|
231
|
-
rubygems_version: 3.
|
232
|
+
rubygems_version: 3.3.3
|
232
233
|
signing_key:
|
233
234
|
specification_version: 4
|
234
235
|
summary: An abstract API base client for service oriented application.
|
@@ -239,7 +240,7 @@ test_files:
|
|
239
240
|
- spec/acfs/global_spec.rb
|
240
241
|
- spec/acfs/location_spec.rb
|
241
242
|
- spec/acfs/middleware/json_spec.rb
|
242
|
-
- spec/acfs/middleware/
|
243
|
+
- spec/acfs/middleware/message_pack_spec.rb
|
243
244
|
- spec/acfs/operation_spec.rb
|
244
245
|
- spec/acfs/request/callbacks_spec.rb
|
245
246
|
- spec/acfs/request_spec.rb
|
@@ -255,7 +256,7 @@ test_files:
|
|
255
256
|
- spec/acfs/resource/initialization_spec.rb
|
256
257
|
- spec/acfs/resource/loadable_spec.rb
|
257
258
|
- spec/acfs/resource/locatable_spec.rb
|
258
|
-
- spec/acfs/resource/
|
259
|
+
- spec/acfs/resource/persistence_spec.rb
|
259
260
|
- spec/acfs/resource/query_methods_spec.rb
|
260
261
|
- spec/acfs/resource/validation_spec.rb
|
261
262
|
- spec/acfs/response/formats_spec.rb
|