acfs 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +8 -141
- data/CHANGELOG.md +0 -325
- data/LICENSE +0 -22
- data/README.md +0 -334
- data/acfs.gemspec +0 -37
- data/lib/acfs.rb +0 -49
- data/lib/acfs/adapter/base.rb +0 -26
- data/lib/acfs/adapter/typhoeus.rb +0 -60
- data/lib/acfs/collection.rb +0 -27
- data/lib/acfs/collections/paginatable.rb +0 -75
- data/lib/acfs/configuration.rb +0 -113
- data/lib/acfs/errors.rb +0 -106
- data/lib/acfs/global.rb +0 -99
- data/lib/acfs/location.rb +0 -78
- data/lib/acfs/middleware/base.rb +0 -20
- data/lib/acfs/middleware/json.rb +0 -27
- data/lib/acfs/middleware/logger.rb +0 -23
- data/lib/acfs/middleware/msgpack.rb +0 -30
- data/lib/acfs/middleware/print.rb +0 -21
- data/lib/acfs/middleware/serializer.rb +0 -39
- data/lib/acfs/operation.rb +0 -81
- data/lib/acfs/request.rb +0 -36
- data/lib/acfs/request/callbacks.rb +0 -50
- data/lib/acfs/resource.rb +0 -37
- data/lib/acfs/resource/attributes.rb +0 -268
- data/lib/acfs/resource/attributes/base.rb +0 -28
- data/lib/acfs/resource/attributes/boolean.rb +0 -37
- data/lib/acfs/resource/attributes/date_time.rb +0 -31
- data/lib/acfs/resource/attributes/dict.rb +0 -37
- data/lib/acfs/resource/attributes/float.rb +0 -31
- data/lib/acfs/resource/attributes/integer.rb +0 -27
- data/lib/acfs/resource/attributes/list.rb +0 -34
- data/lib/acfs/resource/attributes/string.rb +0 -24
- data/lib/acfs/resource/attributes/uuid.rb +0 -47
- data/lib/acfs/resource/dirty.rb +0 -35
- data/lib/acfs/resource/initialization.rb +0 -29
- data/lib/acfs/resource/loadable.rb +0 -33
- data/lib/acfs/resource/locatable.rb +0 -128
- data/lib/acfs/resource/operational.rb +0 -22
- data/lib/acfs/resource/persistence.rb +0 -257
- data/lib/acfs/resource/query_methods.rb +0 -264
- data/lib/acfs/resource/service.rb +0 -42
- data/lib/acfs/resource/validation.rb +0 -37
- data/lib/acfs/response.rb +0 -28
- data/lib/acfs/response/formats.rb +0 -25
- data/lib/acfs/response/status.rb +0 -31
- data/lib/acfs/rspec.rb +0 -11
- data/lib/acfs/runner.rb +0 -97
- data/lib/acfs/service.rb +0 -91
- data/lib/acfs/service/middleware.rb +0 -56
- data/lib/acfs/service/middleware/stack.rb +0 -63
- data/lib/acfs/singleton_resource.rb +0 -83
- data/lib/acfs/stub.rb +0 -172
- data/lib/acfs/util.rb +0 -20
- data/lib/acfs/version.rb +0 -14
- data/lib/acfs/yard.rb +0 -5
- data/spec/acfs/adapter/typhoeus_spec.rb +0 -28
- data/spec/acfs/collection_spec.rb +0 -155
- data/spec/acfs/configuration_spec.rb +0 -51
- data/spec/acfs/global_spec.rb +0 -137
- data/spec/acfs/location_spec.rb +0 -23
- data/spec/acfs/middleware/json_spec.rb +0 -63
- data/spec/acfs/middleware/msgpack_spec.rb +0 -60
- data/spec/acfs/operation_spec.rb +0 -10
- data/spec/acfs/request/callbacks_spec.rb +0 -46
- data/spec/acfs/request_spec.rb +0 -77
- data/spec/acfs/resource/attributes/boolean_spec.rb +0 -56
- data/spec/acfs/resource/attributes/date_time_spec.rb +0 -49
- data/spec/acfs/resource/attributes/dict_spec.rb +0 -75
- data/spec/acfs/resource/attributes/float_spec.rb +0 -59
- data/spec/acfs/resource/attributes/integer_spec.rb +0 -34
- data/spec/acfs/resource/attributes/list_spec.rb +0 -58
- data/spec/acfs/resource/attributes/uuid_spec.rb +0 -40
- data/spec/acfs/resource/attributes_spec.rb +0 -179
- data/spec/acfs/resource/dirty_spec.rb +0 -47
- data/spec/acfs/resource/initialization_spec.rb +0 -30
- data/spec/acfs/resource/loadable_spec.rb +0 -20
- data/spec/acfs/resource/locatable_spec.rb +0 -116
- data/spec/acfs/resource/persistance_spec.rb +0 -316
- data/spec/acfs/resource/query_methods_spec.rb +0 -541
- data/spec/acfs/resource/validation_spec.rb +0 -127
- data/spec/acfs/response/formats_spec.rb +0 -50
- data/spec/acfs/response/status_spec.rb +0 -69
- data/spec/acfs/runner_spec.rb +0 -97
- data/spec/acfs/service/middleware_spec.rb +0 -33
- data/spec/acfs/service_spec.rb +0 -46
- data/spec/acfs/singleton_resource_spec.rb +0 -15
- data/spec/acfs/stub_spec.rb +0 -343
- data/spec/acfs_spec.rb +0 -203
- data/spec/fixtures/config.yml +0 -14
- data/spec/spec_helper.rb +0 -41
- data/spec/support/hash.rb +0 -9
- data/spec/support/response.rb +0 -10
- data/spec/support/service.rb +0 -91
- data/spec/support/shared/find_callbacks.rb +0 -48
data/spec/acfs_spec.rb
DELETED
@@ -1,203 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Acfs' do
|
4
|
-
before do
|
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'}])
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should update single resource synchronously' do
|
14
|
-
stub = stub_request(:put, 'http://users.example.org/users/2')
|
15
|
-
.to_return {|request| {body: request.body, headers: {'Content-Type' => request.headers['Content-Type']}} }
|
16
|
-
|
17
|
-
@user = MyUser.find 2
|
18
|
-
Acfs.run
|
19
|
-
|
20
|
-
expect(@user).to_not be_changed
|
21
|
-
expect(@user).to be_persisted
|
22
|
-
|
23
|
-
@user.name = 'Johnny'
|
24
|
-
|
25
|
-
expect(@user).to be_changed
|
26
|
-
expect(@user).to be_persisted
|
27
|
-
|
28
|
-
@user.save
|
29
|
-
|
30
|
-
expect(stub).to have_been_requested
|
31
|
-
expect(@user).to_not be_changed
|
32
|
-
expect(@user).to be_persisted
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should create a single resource synchronously' do
|
36
|
-
stub = stub_request(:post, 'http://users.example.org/sessions').to_return response(id: 'sessionhash', user: 1)
|
37
|
-
|
38
|
-
session = Session.create ident: 'Anon'
|
39
|
-
|
40
|
-
expect(stub).to have_been_requested
|
41
|
-
expect(session.id).to be == 'sessionhash'
|
42
|
-
expect(session.user).to be == 1
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should load single resource' do
|
46
|
-
@user = MyUser.find(2)
|
47
|
-
|
48
|
-
expect(@user).to_not be_loaded
|
49
|
-
|
50
|
-
Acfs.run
|
51
|
-
|
52
|
-
expect(@user).to be_loaded
|
53
|
-
expect(@user.id).to be == 2
|
54
|
-
expect(@user.name).to be == 'John'
|
55
|
-
expect(@user.age).to be == 26
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'singleton' do
|
59
|
-
before do
|
60
|
-
stub_request(:get, 'http://users.example.org/singles?user_id=5').to_return response(score: 250, user_id: 5)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should create a singleton resource' do
|
64
|
-
stub = stub_request(:post, 'http://users.example.org/singles').to_return response(score: 250, user_id: 5)
|
65
|
-
|
66
|
-
@single = Single.new user_id: 5, score: 250
|
67
|
-
expect(@single.new?).to eq true
|
68
|
-
|
69
|
-
@single.save
|
70
|
-
expect(stub).to have_been_requested
|
71
|
-
|
72
|
-
expect(@single.new?).to eq false
|
73
|
-
expect(@single.user_id).to eq 5
|
74
|
-
expect(@single.score).to eq 250
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should load singleton resource' do
|
78
|
-
@single = Single.find user_id: 5
|
79
|
-
Acfs.run
|
80
|
-
|
81
|
-
expect(@single.score).to eq 250
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should update singleton resource' do
|
85
|
-
stub = stub_request(:put, 'http://users.example.org/singles').to_return do |request|
|
86
|
-
{
|
87
|
-
body: request.body,
|
88
|
-
headers: {'Content-Type' => request.headers['Content-Type']}
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
@single = Single.find user_id: 5
|
93
|
-
Acfs.run
|
94
|
-
|
95
|
-
expect(@single.score).to eq 250
|
96
|
-
|
97
|
-
@single.score = 300
|
98
|
-
@single.save
|
99
|
-
|
100
|
-
expect(stub).to have_been_requested
|
101
|
-
|
102
|
-
expect(@single.score).to eq 300
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should delete singleton resource' do
|
106
|
-
stub = stub_request(:delete, 'http://users.example.org/singles').to_return do |request|
|
107
|
-
{
|
108
|
-
body: request.body,
|
109
|
-
headers: {'Content-Type' => request.headers['Content-Type']}
|
110
|
-
}
|
111
|
-
end
|
112
|
-
|
113
|
-
@single = Single.find user_id: 5
|
114
|
-
Acfs.run
|
115
|
-
|
116
|
-
expect(@single.new?).to eq false
|
117
|
-
|
118
|
-
@single.delete
|
119
|
-
|
120
|
-
expect(stub).to have_been_requested
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'should raise error when calling `all\'' do
|
124
|
-
expect { Single.all }.to raise_error ::Acfs::UnsupportedOperation
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'should load multiple single resources' do
|
129
|
-
@users = MyUser.find([2, 3, 100]) do |users|
|
130
|
-
# This block should be called only after *all* resources are loaded.
|
131
|
-
@john = users[0]
|
132
|
-
@mirx = users[1]
|
133
|
-
@jimy = users[2]
|
134
|
-
end
|
135
|
-
|
136
|
-
expect(@users).to_not be_loaded
|
137
|
-
|
138
|
-
Acfs.run
|
139
|
-
|
140
|
-
expect(@users).to be_loaded
|
141
|
-
expect(@users).to have(3).items
|
142
|
-
|
143
|
-
expect(@users[0].id).to be == 2
|
144
|
-
expect(@users[0].name).to be == 'John'
|
145
|
-
expect(@users[0].age).to be == 26
|
146
|
-
expect(@users[0]).to be == @john
|
147
|
-
|
148
|
-
expect(@users[1].id).to be == 3
|
149
|
-
expect(@users[1].name).to be == 'Miraculix'
|
150
|
-
expect(@users[1].age).to be == 122
|
151
|
-
expect(@users[1]).to be == @mirx
|
152
|
-
|
153
|
-
expect(@users[2].id).to be == 100
|
154
|
-
expect(@users[2].name).to be == 'Jimmy'
|
155
|
-
expect(@users[2].age).to be == 45
|
156
|
-
expect(@users[2]).to be == @jimy
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'should load multiple resources' do
|
160
|
-
@users = MyUser.all
|
161
|
-
|
162
|
-
expect(@users).to_not be_loaded
|
163
|
-
|
164
|
-
Acfs.run
|
165
|
-
|
166
|
-
expect(@users).to be_loaded
|
167
|
-
expect(@users).to have(2).items
|
168
|
-
expect(@users[0].name).to be == 'Anon'
|
169
|
-
expect(@users[0].age).to be == 12
|
170
|
-
expect(@users[1].name).to be == 'John'
|
171
|
-
expect(@users[1].age).to be == 26
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'should load associated resources' do
|
175
|
-
pending 'TODO: Implement high level feature'
|
176
|
-
|
177
|
-
@user = MyUser.find(2) do |user|
|
178
|
-
@friends = user.friends.all
|
179
|
-
end
|
180
|
-
|
181
|
-
Acfs.run
|
182
|
-
|
183
|
-
expect(@user.name).to be == 'John'
|
184
|
-
expect(@user.age).to be == 26
|
185
|
-
|
186
|
-
expect(@friends).to have(1).items
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'should load associated resources from different service' do
|
190
|
-
@user = MyUser.find 2 do |user|
|
191
|
-
expect(user.id).to be == 2
|
192
|
-
@comments = Comment.where user: user.id
|
193
|
-
end
|
194
|
-
|
195
|
-
Acfs.run
|
196
|
-
|
197
|
-
expect(@user.id).to be == 2
|
198
|
-
expect(@user.name).to be == 'John'
|
199
|
-
expect(@user.age).to be == 26
|
200
|
-
|
201
|
-
expect(@comments).to have(2).items
|
202
|
-
end
|
203
|
-
end
|
data/spec/fixtures/config.yml
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
development: &dev
|
2
|
-
services:
|
3
|
-
user_service: http://localhost:3001/
|
4
|
-
comment_service:
|
5
|
-
locate: http://localhost:3002/
|
6
|
-
|
7
|
-
production:
|
8
|
-
services:
|
9
|
-
user_service:
|
10
|
-
locate: http://user.example.org/
|
11
|
-
comment_service: http://comment.example.org/
|
12
|
-
|
13
|
-
test:
|
14
|
-
<<: *dev
|
data/spec/spec_helper.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'webmock/rspec'
|
3
|
-
|
4
|
-
require 'simplecov'
|
5
|
-
SimpleCov.start do
|
6
|
-
add_filter 'spec'
|
7
|
-
end
|
8
|
-
|
9
|
-
if ENV['CI']
|
10
|
-
require 'codecov'
|
11
|
-
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
12
|
-
end
|
13
|
-
|
14
|
-
require 'bundler'
|
15
|
-
Bundler.require(:default, :test)
|
16
|
-
|
17
|
-
require 'acfs'
|
18
|
-
require 'webmock/rspec'
|
19
|
-
|
20
|
-
Dir[File.expand_path('spec/support/**/*.rb')].each {|f| require f }
|
21
|
-
|
22
|
-
RSpec.configure do |config|
|
23
|
-
# ## Mock Framework
|
24
|
-
#
|
25
|
-
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
26
|
-
#
|
27
|
-
# config.mock_with :mocha
|
28
|
-
# config.mock_with :flexmock
|
29
|
-
# config.mock_with :rr
|
30
|
-
|
31
|
-
# Run specs in random order to surface order dependencies. If you find an
|
32
|
-
# order dependency and want to debug it, you can fix the order by providing
|
33
|
-
# the seed, which is printed after each run.
|
34
|
-
# --seed 1234
|
35
|
-
config.order = 'random'
|
36
|
-
|
37
|
-
config.before :each do
|
38
|
-
Acfs.runner.clear
|
39
|
-
Acfs::Stub.clear
|
40
|
-
end
|
41
|
-
end
|
data/spec/support/hash.rb
DELETED
data/spec/support/response.rb
DELETED
data/spec/support/service.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
|
2
|
-
Acfs.configure do
|
3
|
-
locate :user_service, 'http://users.example.org'
|
4
|
-
locate :computer_service, 'http://computers.example.org'
|
5
|
-
locate :comments, 'http://comments.example.org'
|
6
|
-
end
|
7
|
-
|
8
|
-
class UserService < Acfs::Service
|
9
|
-
use Acfs::Middleware::MessagePackDecoder
|
10
|
-
use Acfs::Middleware::JsonDecoder
|
11
|
-
use Acfs::Middleware::JsonEncoder
|
12
|
-
end
|
13
|
-
|
14
|
-
class CommentService < Acfs::Service
|
15
|
-
identity :comments
|
16
|
-
|
17
|
-
use Acfs::Middleware::JsonDecoder
|
18
|
-
end
|
19
|
-
|
20
|
-
class MyUser < Acfs::Resource
|
21
|
-
service UserService, path: 'users'
|
22
|
-
|
23
|
-
attribute :id, :integer
|
24
|
-
attribute :name, :string, default: 'Anon'
|
25
|
-
attribute :age, :integer
|
26
|
-
end
|
27
|
-
|
28
|
-
class Profile < Acfs::SingletonResource
|
29
|
-
service UserService, path: 'users/:user_id/profile'
|
30
|
-
|
31
|
-
attribute :user_id, :integer
|
32
|
-
attribute :twitter_handle, :string
|
33
|
-
end
|
34
|
-
|
35
|
-
class Customer < MyUser
|
36
|
-
end
|
37
|
-
|
38
|
-
class MyUserWithValidations < MyUser
|
39
|
-
validates_presence_of :name, :age
|
40
|
-
validates_format_of :name, with: /\A\w+\s+\w+.?\z/
|
41
|
-
end
|
42
|
-
|
43
|
-
class Session < Acfs::Resource
|
44
|
-
service UserService, path: {
|
45
|
-
list: 'users/:user_id/sessions',
|
46
|
-
delete: 'users/:user_id/sessions/del/:id',
|
47
|
-
update: nil
|
48
|
-
}
|
49
|
-
|
50
|
-
attribute :id, :string
|
51
|
-
attribute :user, :integer
|
52
|
-
end
|
53
|
-
|
54
|
-
class Comment < Acfs::Resource
|
55
|
-
service CommentService
|
56
|
-
|
57
|
-
attribute :id, :integer
|
58
|
-
attribute :text, :string
|
59
|
-
end
|
60
|
-
|
61
|
-
class ComputerService < Acfs::Service
|
62
|
-
use Acfs::Middleware::MessagePackDecoder
|
63
|
-
use Acfs::Middleware::JsonDecoder
|
64
|
-
use Acfs::Middleware::JsonEncoder
|
65
|
-
end
|
66
|
-
|
67
|
-
class Computer < Acfs::Resource
|
68
|
-
service ComputerService, path: 'computers'
|
69
|
-
|
70
|
-
attribute :id, :integer
|
71
|
-
end
|
72
|
-
|
73
|
-
class PC < Computer
|
74
|
-
end
|
75
|
-
|
76
|
-
class Mac < Computer
|
77
|
-
end
|
78
|
-
|
79
|
-
class Single < Acfs::SingletonResource
|
80
|
-
service UserService
|
81
|
-
|
82
|
-
attribute :score, :integer
|
83
|
-
attribute :user_id, :integer
|
84
|
-
end
|
85
|
-
|
86
|
-
class PathArguments < Acfs::Resource
|
87
|
-
service UserService, path: ':required_arg/users/'
|
88
|
-
|
89
|
-
attribute :id, :integer
|
90
|
-
attribute :required_arg, :string
|
91
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
shared_examples 'a query method with multi-callback support' do
|
2
|
-
let(:cb) { Proc.new }
|
3
|
-
|
4
|
-
it 'should invoke callback' do
|
5
|
-
expect do |cb|
|
6
|
-
action.call cb
|
7
|
-
Acfs.run
|
8
|
-
end.to yield_with_args
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should invoke multiple callbacks' do
|
12
|
-
expect do |cb|
|
13
|
-
object = action.call cb
|
14
|
-
Acfs.add_callback object, &cb
|
15
|
-
Acfs.run
|
16
|
-
end.to yield_control.exactly(2).times
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'callback' do
|
20
|
-
it 'should be invoked with resource' do
|
21
|
-
proc = proc {}
|
22
|
-
expect(proc).to receive(:call) do |res|
|
23
|
-
expect(res).to equal @object
|
24
|
-
expect(res).to be_loaded
|
25
|
-
end
|
26
|
-
|
27
|
-
@object = action.call proc
|
28
|
-
Acfs.run
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should invoke multiple callback with loaded resource' do
|
32
|
-
proc1 = proc {}
|
33
|
-
proc2 = proc {}
|
34
|
-
expect(proc1).to receive(:call) do |user|
|
35
|
-
expect(user).to equal @object
|
36
|
-
expect(user).to be_loaded
|
37
|
-
end
|
38
|
-
expect(proc2).to receive(:call) do |user|
|
39
|
-
expect(user).to equal @object
|
40
|
-
expect(user).to be_loaded
|
41
|
-
end
|
42
|
-
|
43
|
-
@object = action.call proc1
|
44
|
-
Acfs.add_callback(@object, &proc2)
|
45
|
-
Acfs.run
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|