acfs 0.42.0 → 0.43.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 +6 -0
- data/README.md +8 -9
- data/acfs.gemspec +3 -3
- data/lib/acfs.rb +0 -2
- data/lib/acfs/adapter/base.rb +0 -2
- data/lib/acfs/adapter/typhoeus.rb +6 -9
- data/lib/acfs/collection.rb +3 -3
- data/lib/acfs/collections/paginatable.rb +16 -16
- data/lib/acfs/configuration.rb +3 -5
- data/lib/acfs/errors.rb +8 -7
- data/lib/acfs/global.rb +1 -1
- data/lib/acfs/location.rb +11 -11
- data/lib/acfs/middleware/base.rb +1 -2
- data/lib/acfs/middleware/json.rb +0 -1
- data/lib/acfs/middleware/logger.rb +0 -2
- data/lib/acfs/middleware/print.rb +0 -2
- data/lib/acfs/middleware/serializer.rb +3 -6
- data/lib/acfs/operation.rb +3 -4
- data/lib/acfs/request.rb +2 -3
- data/lib/acfs/request/callbacks.rb +2 -3
- data/lib/acfs/resource.rb +34 -5
- data/lib/acfs/{model → resource}/attributes.rb +70 -46
- data/lib/acfs/{model → resource}/attributes/base.rb +10 -6
- data/lib/acfs/resource/attributes/boolean.rb +33 -0
- data/lib/acfs/resource/attributes/date_time.rb +32 -0
- data/lib/acfs/{model → resource}/attributes/dict.rb +1 -3
- data/lib/acfs/{model → resource}/attributes/float.rb +3 -6
- data/lib/acfs/{model → resource}/attributes/integer.rb +3 -6
- data/lib/acfs/{model → resource}/attributes/list.rb +2 -5
- data/lib/acfs/{model → resource}/attributes/string.rb +4 -6
- data/lib/acfs/{model → resource}/attributes/uuid.rb +18 -8
- data/lib/acfs/resource/dirty.rb +47 -0
- data/lib/acfs/{model → resource}/initialization.rb +8 -10
- data/lib/acfs/{model → resource}/loadable.rb +3 -4
- data/lib/acfs/{model → resource}/locatable.rb +22 -23
- data/lib/acfs/{model → resource}/operational.rb +2 -3
- data/lib/acfs/resource/persistence.rb +257 -0
- data/lib/acfs/{model → resource}/query_methods.rb +81 -66
- data/lib/acfs/{model → resource}/service.rb +10 -9
- data/lib/acfs/resource/validation.rb +28 -0
- data/lib/acfs/response.rb +1 -2
- data/lib/acfs/response/formats.rb +1 -2
- data/lib/acfs/response/status.rb +3 -5
- data/lib/acfs/runner.rb +4 -5
- data/lib/acfs/service.rb +4 -6
- data/lib/acfs/service/middleware.rb +1 -3
- data/lib/acfs/singleton_resource.rb +11 -24
- data/lib/acfs/stub.rb +30 -22
- data/lib/acfs/util.rb +1 -1
- data/lib/acfs/version.rb +4 -2
- data/spec/acfs/adapter/typhoeus_spec.rb +4 -4
- data/spec/acfs/collection_spec.rb +33 -33
- data/spec/acfs/configuration_spec.rb +0 -1
- data/spec/acfs/global_spec.rb +3 -3
- data/spec/acfs/middleware/json_spec.rb +2 -2
- data/spec/acfs/middleware/msgpack_spec.rb +4 -4
- data/spec/acfs/request/callbacks_spec.rb +8 -8
- data/spec/acfs/request_spec.rb +5 -5
- data/spec/acfs/{model → resource}/attributes/boolean_spec.rb +2 -2
- data/spec/acfs/{model → resource}/attributes/date_time_spec.rb +7 -7
- data/spec/acfs/{model → resource}/attributes/dict_spec.rb +6 -6
- data/spec/acfs/{model → resource}/attributes/float_spec.rb +3 -3
- data/spec/acfs/{model → resource}/attributes/list_spec.rb +5 -5
- data/spec/acfs/{model → resource}/attributes/uuid_spec.rb +6 -6
- data/spec/acfs/{model → resource}/attributes_spec.rb +31 -17
- data/spec/acfs/{model → resource}/dirty_spec.rb +7 -5
- data/spec/acfs/{model → resource}/initialization_spec.rb +7 -7
- data/spec/acfs/{model → resource}/loadable_spec.rb +4 -3
- data/spec/acfs/{model → resource}/locatable_spec.rb +24 -14
- data/spec/acfs/{model → resource}/persistance_spec.rb +34 -34
- data/spec/acfs/{model → resource}/query_methods_spec.rb +171 -130
- data/spec/acfs/{model → resource}/validation_spec.rb +5 -6
- data/spec/acfs/response/formats_spec.rb +1 -1
- data/spec/acfs/response/status_spec.rb +1 -1
- data/spec/acfs/runner_spec.rb +2 -3
- data/spec/acfs/service/middleware_spec.rb +1 -1
- data/spec/acfs/service_spec.rb +3 -5
- data/spec/acfs/singleton_resource_spec.rb +3 -3
- data/spec/acfs/stub_spec.rb +52 -24
- data/spec/acfs_spec.rb +22 -19
- data/spec/spec_helper.rb +1 -1
- data/spec/support/hash.rb +9 -0
- data/spec/support/service.rb +4 -7
- data/spec/support/shared/find_callbacks.rb +7 -7
- metadata +52 -52
- data/lib/acfs/model.rb +0 -43
- data/lib/acfs/model/attributes/boolean.rb +0 -38
- data/lib/acfs/model/attributes/date_time.rb +0 -30
- data/lib/acfs/model/dirty.rb +0 -49
- data/lib/acfs/model/persistence.rb +0 -243
- data/lib/acfs/model/relations.rb +0 -10
- data/lib/acfs/model/validation.rb +0 -30
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Acfs::
|
3
|
+
describe Acfs::Resource::Validation do
|
4
4
|
let(:params) { {name: 'john smith', age: 24} }
|
5
5
|
let(:model) { MyUserWithValidations.new params }
|
6
6
|
|
@@ -23,7 +23,7 @@ describe Acfs::Model::Validation do
|
|
23
23
|
after { Acfs::Stub.disable }
|
24
24
|
|
25
25
|
before do
|
26
|
-
Acfs::Stub.resource MyUser, :create,
|
26
|
+
Acfs::Stub.resource MyUser, :create, return: {errors: {name: ['can\'t be blank']}}, raise: 422
|
27
27
|
end
|
28
28
|
|
29
29
|
let(:params) { {} }
|
@@ -34,7 +34,7 @@ describe Acfs::Model::Validation do
|
|
34
34
|
|
35
35
|
it 'should not override errors' do
|
36
36
|
subject.valid?
|
37
|
-
expect(subject.errors.to_hash).to eq(
|
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::Model::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(
|
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::Model::Validation do
|
|
96
96
|
|
97
97
|
context 'on changed resource' do
|
98
98
|
before { model.loaded! }
|
99
|
-
let(:model) { super().tap {
|
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,6 +106,5 @@ describe Acfs::Model::Validation do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
describe 'validates with context' do
|
109
|
-
|
110
109
|
end
|
111
110
|
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) { {
|
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 }
|
@@ -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) { {
|
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 }
|
data/spec/acfs/runner_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class NullAdapter < Acfs::Adapter::Base
|
4
|
-
|
5
4
|
# Start processing queued requests.
|
6
5
|
#
|
7
6
|
def start
|
@@ -46,8 +45,8 @@ describe ::Acfs::Runner do
|
|
46
45
|
|
47
46
|
describe '#instrumentation' do
|
48
47
|
before do
|
49
|
-
::ActiveSupport::Notifications.subscribe
|
50
|
-
::ActiveSupport::Notifications.subscribe
|
48
|
+
::ActiveSupport::Notifications.subscribe(/^acfs\.runner/, collector)
|
49
|
+
::ActiveSupport::Notifications.subscribe(/^acfs\.operation/, collector2)
|
51
50
|
end
|
52
51
|
|
53
52
|
describe '#process' do
|
data/spec/acfs/service_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Acfs::Service do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '#initialize' do
|
13
|
-
let(:options) { {
|
13
|
+
let(:options) { {path: 'abc', key: 'value'} }
|
14
14
|
|
15
15
|
it 'should set options' do
|
16
16
|
expect(service.options).to eq(options)
|
@@ -19,14 +19,14 @@ describe Acfs::Service do
|
|
19
19
|
|
20
20
|
describe '#location' do
|
21
21
|
let(:resource) { Class.new }
|
22
|
-
before { allow(resource).to receive(:location_default_path, &proc{|
|
22
|
+
before { allow(resource).to receive(:location_default_path, &proc{|_a, p| p}) }
|
23
23
|
|
24
24
|
it 'should extract resource path name from given class' do
|
25
25
|
expect(service.location(resource).to_s).to eq('/classes')
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'with path options' do
|
29
|
-
let(:options) { {
|
29
|
+
let(:options) { {path: 'abc'} }
|
30
30
|
|
31
31
|
it 'should have custom resource path' do
|
32
32
|
expect(service.location(resource).to_s).to eq('/abc')
|
@@ -35,13 +35,11 @@ describe Acfs::Service do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '.base_url' do
|
38
|
-
|
39
38
|
before do
|
40
39
|
Acfs::Configuration.current.locate :test, 'http://abc.de/api/v1'
|
41
40
|
end
|
42
41
|
|
43
42
|
it 'should return configured URI for service' do
|
44
|
-
|
45
43
|
expect(srv_class.base_url).to eq('http://abc.de/api/v1')
|
46
44
|
end
|
47
45
|
end
|
@@ -5,11 +5,11 @@ describe Acfs::SingletonResource do
|
|
5
5
|
|
6
6
|
describe '.find' do
|
7
7
|
before do
|
8
|
-
stub_request(:get, 'http://users.example.org/singles')
|
8
|
+
stub_request(:get, 'http://users.example.org/singles')
|
9
|
+
.to_return response id: 1
|
9
10
|
end
|
10
11
|
|
11
|
-
let(:action) {
|
12
|
+
let(:action) { ->(cb) { model.find(&cb) } }
|
12
13
|
it_should_behave_like 'a query method with multi-callback support'
|
13
14
|
end
|
14
|
-
|
15
15
|
end
|
data/spec/acfs/stub_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe Acfs::Stub do
|
|
14
14
|
|
15
15
|
describe '#called?' do
|
16
16
|
context 'without specified number' do
|
17
|
-
let!(:operation) { Acfs::Stub.resource MyUser, :read, with: {
|
17
|
+
let!(:operation) { Acfs::Stub.resource MyUser, :read, with: {id: 1}, return: {id: 1, name: 'John Smith', age: 32} }
|
18
18
|
|
19
19
|
it 'should allow to test if stub was called' do
|
20
20
|
MyUser.find 1
|
@@ -38,8 +38,8 @@ describe Acfs::Stub do
|
|
38
38
|
describe '.resource' do
|
39
39
|
context 'with ambiguous stubs' do
|
40
40
|
before do
|
41
|
-
Acfs::Stub.resource MyUser, :read, with: {
|
42
|
-
Acfs::Stub.resource MyUser, :read, with: {
|
41
|
+
Acfs::Stub.resource MyUser, :read, with: {id: 1}, return: {id: 1, name: 'John Smith', age: 32}
|
42
|
+
Acfs::Stub.resource MyUser, :read, with: {id: 1}, raise: :not_found
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'should raise error' do
|
@@ -51,9 +51,9 @@ describe Acfs::Stub do
|
|
51
51
|
|
52
52
|
context 'with read action' do
|
53
53
|
before do
|
54
|
-
Acfs::Stub.resource MyUser, :read, with: {
|
55
|
-
Acfs::Stub.resource MyUser, :read, with: {
|
56
|
-
Acfs::Stub.resource MyUser, :read, with: {
|
54
|
+
Acfs::Stub.resource MyUser, :read, with: {id: 1}, return: {id: 1, name: 'John Smith', age: 32}
|
55
|
+
Acfs::Stub.resource MyUser, :read, with: {id: 2}, raise: SpecialCustomError
|
56
|
+
Acfs::Stub.resource MyUser, :read, with: {id: 3}, raise: :not_found
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'should allow to stub resource reads' do
|
@@ -81,8 +81,8 @@ describe Acfs::Stub do
|
|
81
81
|
|
82
82
|
context 'with type parameter' do
|
83
83
|
before do
|
84
|
-
Acfs::Stub.resource Computer, :read, with: {
|
85
|
-
Acfs::Stub.resource Computer, :read, with: {
|
84
|
+
Acfs::Stub.resource Computer, :read, with: {id: 1}, return: {id: 1, type: 'PC'}
|
85
|
+
Acfs::Stub.resource Computer, :read, with: {id: 2}, return: {id: 2, type: 'Mac'}
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'should create inherited type' do
|
@@ -99,8 +99,8 @@ describe Acfs::Stub do
|
|
99
99
|
|
100
100
|
context 'with create action' do
|
101
101
|
before do
|
102
|
-
Acfs::Stub.resource Session, :create, with: {
|
103
|
-
Acfs::Stub.resource Session, :create, with:
|
102
|
+
Acfs::Stub.resource Session, :create, with: {ident: 'john@exmaple.org', password: 's3cr3t'}, return: {id: 'longhash', user: 1}
|
103
|
+
Acfs::Stub.resource Session, :create, with: ->(op) { op.data[:ident] == 'john@exmaple.org' && op.data[:password] == 'wrong' }, raise: 422
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'should allow stub resource creation' do
|
@@ -111,16 +111,16 @@ describe Acfs::Stub do
|
|
111
111
|
end
|
112
112
|
|
113
113
|
it 'should allow to raise error' do
|
114
|
-
expect
|
114
|
+
expect do
|
115
115
|
Session.create! ident: 'john@exmaple.org', password: 'wrong'
|
116
|
-
|
116
|
+
end.to raise_error(::Acfs::InvalidResource)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
context 'with list action' do
|
121
121
|
before do
|
122
122
|
Acfs::Stub.resource MyUser, :list,
|
123
|
-
return: [{
|
123
|
+
return: [{id: 1, name: 'John Smith', age: 32}, {id: 2, name: 'Anon', age: 12}]
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'should return collection' do
|
@@ -158,8 +158,8 @@ describe Acfs::Stub do
|
|
158
158
|
context 'with header' do
|
159
159
|
before do
|
160
160
|
Acfs::Stub.resource Comment, :list,
|
161
|
-
|
162
|
-
|
161
|
+
return: [{id: 1, text: 'Foo'}, {id: 2, text: 'Bar'}],
|
162
|
+
headers: headers
|
163
163
|
end
|
164
164
|
|
165
165
|
let!(:comments) { Comment.all }
|
@@ -172,9 +172,15 @@ describe Acfs::Stub do
|
|
172
172
|
|
173
173
|
context 'with update action' do
|
174
174
|
before do
|
175
|
-
Acfs::Stub.resource MyUser, :read, with: {
|
176
|
-
Acfs::Stub.resource MyUser, :update, with: {
|
177
|
-
Acfs::Stub.resource MyUser, :update, with: {
|
175
|
+
Acfs::Stub.resource MyUser, :read, with: {id: 1}, return: {id: 1, name: 'John Smith', age: 32}
|
176
|
+
Acfs::Stub.resource MyUser, :update, with: {id: 1, name: 'John Smith', age: 22}, return: {id: 1, name: 'John Smith', age: 23}
|
177
|
+
Acfs::Stub.resource MyUser, :update, with: {id: 1, name: 'John Smith', age: 0}, raise: 422
|
178
|
+
end
|
179
|
+
|
180
|
+
let!(:update_stub) do
|
181
|
+
Acfs::Stub.resource MyUser, :update,
|
182
|
+
with: {id: 1, name: 'Jane Smith'},
|
183
|
+
return: ->(op) { Hash[op.data.map {|k, v| [k, v.to_s.upcase] }] }
|
178
184
|
end
|
179
185
|
|
180
186
|
it 'should allow stub resource update' do
|
@@ -194,9 +200,31 @@ describe Acfs::Stub do
|
|
194
200
|
user.age = 0
|
195
201
|
user.save
|
196
202
|
|
197
|
-
expect
|
203
|
+
expect do
|
198
204
|
user.save!
|
199
|
-
|
205
|
+
end.to raise_error(::Acfs::InvalidResource)
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should match partial :with' do
|
209
|
+
user = MyUser.find 1
|
210
|
+
Acfs.run
|
211
|
+
|
212
|
+
user.age = 5
|
213
|
+
user.name = 'Jane Smith'
|
214
|
+
user.save!
|
215
|
+
|
216
|
+
expect(update_stub).to be_called
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should process response body' do
|
220
|
+
user = MyUser.find 1
|
221
|
+
Acfs.run
|
222
|
+
|
223
|
+
user.age = 5
|
224
|
+
user.name = 'Jane Smith'
|
225
|
+
user.save!
|
226
|
+
|
227
|
+
expect(user.name).to eq 'JANE SMITH'
|
200
228
|
end
|
201
229
|
end
|
202
230
|
|
@@ -206,9 +234,9 @@ describe Acfs::Stub do
|
|
206
234
|
end
|
207
235
|
|
208
236
|
it 'should allow to raise error' do
|
209
|
-
expect
|
210
|
-
|
211
|
-
|
237
|
+
expect do
|
238
|
+
MyUser.create! name: 'John Smith', age: 0
|
239
|
+
end.to raise_error(::Acfs::InvalidResource)
|
212
240
|
end
|
213
241
|
end
|
214
242
|
end
|
@@ -217,7 +245,7 @@ describe Acfs::Stub do
|
|
217
245
|
context 'when enabled' do
|
218
246
|
before do
|
219
247
|
Acfs::Stub.allow_requests = true
|
220
|
-
stub_request(:get, 'http://users.example.org/users/2').to_return response(
|
248
|
+
stub_request(:get, 'http://users.example.org/users/2').to_return response(id: 2, name: 'John', age: 26)
|
221
249
|
end
|
222
250
|
|
223
251
|
it 'should allow real requests' do
|
data/spec/acfs_spec.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Acfs' do
|
4
|
-
|
5
4
|
before do
|
6
|
-
stub_request(:get, 'http://users.example.org/users').to_return response([{
|
7
|
-
stub_request(:get, 'http://users.example.org/users/2').to_return response(
|
8
|
-
stub_request(:get, 'http://users.example.org/users/3').to_return response(
|
9
|
-
stub_request(:get, 'http://users.example.org/users/100').to_return response(
|
10
|
-
stub_request(:get, 'http://users.example.org/users/2/friends').to_return response([{
|
11
|
-
stub_request(:get, 'http://comments.example.org/comments?user=2').to_return response([{
|
5
|
+
stub_request(:get, 'http://users.example.org/users').to_return response([{id: 1, name: 'Anon', age: 12}, {id: 2, name: 'John', age: 26}])
|
6
|
+
stub_request(:get, 'http://users.example.org/users/2').to_return response(id: 2, name: 'John', age: 26)
|
7
|
+
stub_request(:get, 'http://users.example.org/users/3').to_return response(id: 3, name: 'Miraculix', age: 122)
|
8
|
+
stub_request(:get, 'http://users.example.org/users/100').to_return response(id: 100, name: 'Jimmy', age: 45)
|
9
|
+
stub_request(:get, 'http://users.example.org/users/2/friends').to_return response([{id: 1, name: 'Anon', age: 12}])
|
10
|
+
stub_request(:get, 'http://comments.example.org/comments?user=2').to_return response([{id: 1, text: 'Comment #1'}, {id: 2, text: 'Comment #2'}])
|
12
11
|
end
|
13
12
|
|
14
13
|
it 'should update single resource synchronously' do
|
15
14
|
stub = stub_request(:put, 'http://users.example.org/users/2')
|
16
|
-
|
15
|
+
.to_return {|request| {body: request.body, headers: {'Content-Type' => request.headers['Content-Type']}} }
|
17
16
|
|
18
17
|
@user = MyUser.find 2
|
19
18
|
Acfs.run
|
@@ -34,7 +33,7 @@ describe 'Acfs' do
|
|
34
33
|
end
|
35
34
|
|
36
35
|
it 'should create a single resource synchronously' do
|
37
|
-
stub = stub_request(:post, 'http://users.example.org/sessions').to_return response(
|
36
|
+
stub = stub_request(:post, 'http://users.example.org/sessions').to_return response(id: 'sessionhash', user: 1)
|
38
37
|
|
39
38
|
session = Session.create ident: 'Anon'
|
40
39
|
|
@@ -58,11 +57,11 @@ describe 'Acfs' do
|
|
58
57
|
|
59
58
|
describe 'singleton' do
|
60
59
|
before do
|
61
|
-
stub_request(:get, 'http://users.example.org/singles?user_id=5').to_return response(
|
60
|
+
stub_request(:get, 'http://users.example.org/singles?user_id=5').to_return response(score: 250, user_id: 5)
|
62
61
|
end
|
63
62
|
|
64
63
|
it 'should create a singleton resource' do
|
65
|
-
stub = stub_request(:post, 'http://users.example.org/singles').to_return response(
|
64
|
+
stub = stub_request(:post, 'http://users.example.org/singles').to_return response(score: 250, user_id: 5)
|
66
65
|
|
67
66
|
@single = Single.new user_id: 5, score: 250
|
68
67
|
expect(@single.new?).to eq true
|
@@ -83,10 +82,12 @@ describe 'Acfs' do
|
|
83
82
|
end
|
84
83
|
|
85
84
|
it 'should update singleton resource' do
|
86
|
-
stub = stub_request(:put, 'http://users.example.org/singles').to_return
|
85
|
+
stub = stub_request(:put, 'http://users.example.org/singles').to_return do |request|
|
86
|
+
{
|
87
87
|
body: request.body,
|
88
|
-
headers: {
|
89
|
-
|
88
|
+
headers: {'Content-Type' => request.headers['Content-Type']}
|
89
|
+
}
|
90
|
+
end
|
90
91
|
|
91
92
|
@single = Single.find user_id: 5
|
92
93
|
Acfs.run
|
@@ -102,10 +103,12 @@ describe 'Acfs' do
|
|
102
103
|
end
|
103
104
|
|
104
105
|
it 'should delete singleton resource' do
|
105
|
-
stub = stub_request(:delete, 'http://users.example.org/singles').to_return
|
106
|
+
stub = stub_request(:delete, 'http://users.example.org/singles').to_return do |request|
|
107
|
+
{
|
106
108
|
body: request.body,
|
107
|
-
headers: {
|
108
|
-
|
109
|
+
headers: {'Content-Type' => request.headers['Content-Type']}
|
110
|
+
}
|
111
|
+
end
|
109
112
|
|
110
113
|
@single = Single.find user_id: 5
|
111
114
|
Acfs.run
|
@@ -118,12 +121,12 @@ describe 'Acfs' do
|
|
118
121
|
end
|
119
122
|
|
120
123
|
it 'should raise error when calling `all\'' do
|
121
|
-
expect {Single.all}.to raise_error
|
124
|
+
expect { Single.all }.to raise_error ::Acfs::UnsupportedOperation
|
122
125
|
end
|
123
126
|
end
|
124
127
|
|
125
128
|
it 'should load multiple single resources' do
|
126
|
-
@users = MyUser.find(2, 3, 100) do |users|
|
129
|
+
@users = MyUser.find([2, 3, 100]) do |users|
|
127
130
|
# This block should be called only after *all* resources are loaded.
|
128
131
|
@john = users[0]
|
129
132
|
@mirx = users[1]
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/service.rb
CHANGED
@@ -33,7 +33,6 @@ class Profile < Acfs::SingletonResource
|
|
33
33
|
end
|
34
34
|
|
35
35
|
class Customer < MyUser
|
36
|
-
|
37
36
|
end
|
38
37
|
|
39
38
|
class MyUserWithValidations < MyUser
|
@@ -43,9 +42,9 @@ end
|
|
43
42
|
|
44
43
|
class Session < Acfs::Resource
|
45
44
|
service UserService, path: {
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
list: 'users/:user_id/sessions',
|
46
|
+
delete: 'users/:user_id/sessions/del/:id',
|
47
|
+
update: nil
|
49
48
|
}
|
50
49
|
|
51
50
|
attribute :id, :string
|
@@ -72,11 +71,9 @@ class Computer < Acfs::Resource
|
|
72
71
|
end
|
73
72
|
|
74
73
|
class PC < Computer
|
75
|
-
|
76
74
|
end
|
77
75
|
|
78
76
|
class Mac < Computer
|
79
|
-
|
80
77
|
end
|
81
78
|
|
82
79
|
class Single < Acfs::SingletonResource
|
@@ -91,4 +88,4 @@ class PathArguments < Acfs::Resource
|
|
91
88
|
|
92
89
|
attribute :id, :integer
|
93
90
|
attribute :required_arg, :string
|
94
|
-
end
|
91
|
+
end
|