acfs 0.33.0 → 0.34.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/doc/file.README.html +1 -1
- data/lib/acfs/collection.rb +2 -0
- data/lib/acfs/collections/paginatable.rb +16 -0
- data/lib/acfs/model/persistence.rb +1 -1
- data/lib/acfs/model/query_methods.rb +3 -2
- data/lib/acfs/operation.rb +1 -1
- data/lib/acfs/parameter_decoder.rb +37 -0
- data/lib/acfs/singleton_resource.rb +1 -10
- data/lib/acfs/stub.rb +2 -1
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs/collection_spec.rb +42 -0
- data/spec/acfs/model/query_methods_spec.rb +35 -60
- data/spec/acfs/model/validation_spec.rb +1 -0
- data/spec/acfs/singleton_resource_spec.rb +15 -0
- data/spec/acfs/stub_spec.rb +14 -0
- data/spec/spec_helper.rb +0 -2
- data/spec/support/shared/find_callbacks.rb +48 -0
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 79f96815f2139c2a96c6c79a311904567483e720
|
|
4
|
+
data.tar.gz: 0dd9f4379210854cda16b5e6e70868c8201d093d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d39d8dcb64e34c8f9ed4962c417958f2de27a811a8caf039cec4ebf2c892fda5839fe17ebfef515e75eab8482bb13976a1c512ff938ef460e9cfd3a98b264ab
|
|
7
|
+
data.tar.gz: 0d054784e48f8c4e9fd7973fb3d8abaf333066960353d653fff930933b0ad041f8ae6d724eaccf8ec54ad37d98b727e8914ebf1b61053072c19368c6e27eff29
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.34.0
|
|
4
|
+
|
|
5
|
+
* Add support for will_paginate view helper used with `Acfs::Collection`s
|
|
6
|
+
* Add support for pagination header added by [paginate-responder](https://github.com/jgraichen/paginate-responder)
|
|
7
|
+
* Improve `Resource#new?` detection by using `loaded?` instead of presence of `:id` attribute
|
|
8
|
+
|
|
3
9
|
## 0.33.0
|
|
4
10
|
|
|
5
11
|
* Do not raise errors on unknown attributes by default, add :unknown option.
|
data/doc/file.README.html
CHANGED
|
@@ -389,7 +389,7 @@ Modified Headers, conflict detection, ...</li>
|
|
|
389
389
|
</div></div>
|
|
390
390
|
|
|
391
391
|
<div id="footer">
|
|
392
|
-
Generated on
|
|
392
|
+
Generated on Fri Mar 7 20:03:40 2014 by
|
|
393
393
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
394
394
|
0.8.7.3 (ruby-2.1.1).
|
|
395
395
|
</div>
|
data/lib/acfs/collection.rb
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
require 'delegate'
|
|
2
2
|
|
|
3
3
|
require 'acfs/model/loadable'
|
|
4
|
+
require 'acfs/collections/paginatable'
|
|
4
5
|
|
|
5
6
|
module Acfs
|
|
6
7
|
|
|
7
8
|
class Collection < ::Delegator
|
|
8
9
|
include Model::Loadable
|
|
9
10
|
include Acfs::Util::Callbacks
|
|
11
|
+
include Collections::Paginatable
|
|
10
12
|
|
|
11
13
|
def initialize
|
|
12
14
|
super([])
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Acfs::Collections
|
|
2
|
+
module Paginatable
|
|
3
|
+
def total_pages
|
|
4
|
+
@total_pages
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def current_page
|
|
8
|
+
@current_page
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def setup_pagination(params, header)
|
|
12
|
+
@current_page = Integer(params.fetch(:page, 1)) rescue params[:page]
|
|
13
|
+
@total_pages = Integer(header['X-Total-Pages']) if header['X-Total-Pages']
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -75,10 +75,11 @@ module Acfs::Model
|
|
|
75
75
|
collection = ::Acfs::Collection.new
|
|
76
76
|
collection.__callbacks__ << block if block
|
|
77
77
|
|
|
78
|
-
operation :list, params: params do |data|
|
|
78
|
+
operation :list, params: params do |data, header|
|
|
79
79
|
data.each do |obj|
|
|
80
80
|
collection << create_resource(obj)
|
|
81
81
|
end
|
|
82
|
+
collection.setup_pagination params, header
|
|
82
83
|
collection.loaded!
|
|
83
84
|
collection.__invoke__
|
|
84
85
|
end
|
|
@@ -137,7 +138,7 @@ module Acfs::Model
|
|
|
137
138
|
model = Acfs::Util::ResourceDelegator.new self.new
|
|
138
139
|
|
|
139
140
|
opts[:params] ||= {}
|
|
140
|
-
opts[:params].merge!({ id: id })
|
|
141
|
+
opts[:params].merge!({ id: id }) unless id.nil?
|
|
141
142
|
|
|
142
143
|
model.__callbacks__ << block unless block.nil?
|
|
143
144
|
|
data/lib/acfs/operation.rb
CHANGED
|
@@ -50,7 +50,7 @@ module Acfs
|
|
|
50
50
|
request = ::Acfs::Request.new url, method: method, params: params, data: data
|
|
51
51
|
request.on_complete do |response|
|
|
52
52
|
handle_failure response unless response.success?
|
|
53
|
-
callback.call response.data
|
|
53
|
+
callback.call response.data, response.headers
|
|
54
54
|
end
|
|
55
55
|
request
|
|
56
56
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Acfs::ParameterDecoder
|
|
2
|
+
|
|
3
|
+
module Functions
|
|
4
|
+
def self.deep_decode(hash)
|
|
5
|
+
return hash unless hash.is_a? Hash
|
|
6
|
+
|
|
7
|
+
hash.each_pair do |key, value|
|
|
8
|
+
if value.is_a? Hash
|
|
9
|
+
deep_decode(value)
|
|
10
|
+
hash[key] = decode_typhoeus_array(value)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.decode_typhoeus_array(hash)
|
|
16
|
+
if typhoeus_encoded? hash
|
|
17
|
+
hash.inject([]) do |memo, (key, val)|
|
|
18
|
+
memo[Integer(key)] = val
|
|
19
|
+
memo
|
|
20
|
+
end
|
|
21
|
+
else
|
|
22
|
+
hash
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.typhoeus_encoded?(hash)
|
|
27
|
+
return false if hash.empty?
|
|
28
|
+
self.keys.sort == (0...hash.keys.size).map { |i| i.to_s }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.included(base)
|
|
33
|
+
base.send :before_filter do
|
|
34
|
+
Functions.deep_decode params
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -72,16 +72,7 @@ module Acfs
|
|
|
72
72
|
# @return [ self ] Resource object.
|
|
73
73
|
#
|
|
74
74
|
def find(*attrs, &block)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
model = Util::ResourceDelegator.new self.new
|
|
78
|
-
|
|
79
|
-
operation :read, opts do |data|
|
|
80
|
-
model.__setobj__ create_resource data, origin: model.__getobj__
|
|
81
|
-
block.call model unless block.nil?
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
model
|
|
75
|
+
find_single nil, params: attrs.extract_options!, &block
|
|
85
76
|
end
|
|
86
77
|
|
|
87
78
|
# @api public
|
data/lib/acfs/stub.rb
CHANGED
data/lib/acfs/version.rb
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Acfs::Collection do
|
|
4
|
+
describe 'Pagination' do
|
|
5
|
+
let(:params) { Hash.new }
|
|
6
|
+
let!(:collection) { MyUser.all params }
|
|
7
|
+
|
|
8
|
+
subject { Acfs.run; collection }
|
|
9
|
+
|
|
10
|
+
context 'without explicit page parameter' do
|
|
11
|
+
before do
|
|
12
|
+
stub_request(:get, 'http://users.example.org/users').to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
|
|
13
|
+
headers: {'X-Total-Pages' => '2'})
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
its(:total_pages) { should eq 2 }
|
|
17
|
+
its(:current_page) { should eq 1 }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'with page parameter' do
|
|
21
|
+
let(:params) { {page: 2} }
|
|
22
|
+
before do
|
|
23
|
+
stub_request(:get, 'http://users.example.org/users?page=2').to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
|
|
24
|
+
headers: {'X-Total-Pages' => '2'})
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
its(:total_pages) { should eq 2 }
|
|
28
|
+
its(:current_page) { should eq 2 }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'with non-numerical page parameter' do
|
|
32
|
+
let(:params) { {page: 'e546f5'} }
|
|
33
|
+
before do
|
|
34
|
+
stub_request(:get, 'http://users.example.org/users?page=e546f5').to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
|
|
35
|
+
headers: {'X-Total-Pages' => '2'})
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
its(:total_pages) { should eq 2 }
|
|
39
|
+
its(:current_page) { should eq 'e546f5' }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -8,43 +8,18 @@ describe Acfs::Model::QueryMethods do
|
|
|
8
8
|
context 'with successful response' do
|
|
9
9
|
before do
|
|
10
10
|
stub_request(:get, 'http://users.example.org/users/1').to_return response({id: 1, name: 'Anon', age: 12, born_at: 'Berlin'})
|
|
11
|
-
stub_request(:get, 'http://users.example.org/users/2').to_return response({id: 2, type: 'Customer', name: 'Clare Customer', age: 24
|
|
11
|
+
stub_request(:get, 'http://users.example.org/users/2').to_return response({id: 2, type: 'Customer', name: 'Clare Customer', age: 24})
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
let(:action) { lambda { |cb=nil| model.find 1, &cb } }
|
|
15
|
+
it_behaves_like 'a query method with multi-callback support'
|
|
16
|
+
|
|
14
17
|
it 'should load a single remote resource' do
|
|
15
|
-
user =
|
|
18
|
+
user = action.call
|
|
16
19
|
Acfs.run
|
|
17
20
|
|
|
18
21
|
expect(user.attributes).to eq(
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'should invoke callback after model is loaded' do
|
|
23
|
-
proc = Proc.new { }
|
|
24
|
-
expect(proc).to receive(:call) do |user|
|
|
25
|
-
expect(user).to equal @user
|
|
26
|
-
expect(user).to be_loaded
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
@user = model.find 1, &proc
|
|
30
|
-
Acfs.run
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it 'should invoke multiple callback after model is loaded' do
|
|
34
|
-
proc1 = Proc.new { }
|
|
35
|
-
proc2 = Proc.new { }
|
|
36
|
-
expect(proc1).to receive(:call) do |user|
|
|
37
|
-
expect(user).to equal @user
|
|
38
|
-
expect(user).to be_loaded
|
|
39
|
-
end
|
|
40
|
-
expect(proc2).to receive(:call) do |user|
|
|
41
|
-
expect(user).to equal @user
|
|
42
|
-
expect(user).to be_loaded
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
@user = model.find 1, &proc1
|
|
46
|
-
Acfs.add_callback(@user, &proc2)
|
|
47
|
-
Acfs.run
|
|
22
|
+
{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}.stringify_keys)
|
|
48
23
|
end
|
|
49
24
|
|
|
50
25
|
context 'with resource type inheritance' do
|
|
@@ -65,7 +40,7 @@ describe Acfs::Model::QueryMethods do
|
|
|
65
40
|
|
|
66
41
|
context 'with 404 response' do
|
|
67
42
|
before do
|
|
68
|
-
stub_request(:get, 'http://users.example.org/users/1').to_return response({
|
|
43
|
+
stub_request(:get, 'http://users.example.org/users/1').to_return response({error: 'not found'}, status: 404)
|
|
69
44
|
end
|
|
70
45
|
|
|
71
46
|
it 'should raise a NotFound error' do
|
|
@@ -94,10 +69,10 @@ describe Acfs::Model::QueryMethods do
|
|
|
94
69
|
|
|
95
70
|
context 'with multiple ids' do
|
|
96
71
|
before do
|
|
97
|
-
stub_request(:get, 'http://users.example.org/users/1').to_return response({
|
|
98
|
-
stub_request(:get, 'http://users.example.org/users/2').to_return response({
|
|
99
|
-
stub_request(:get, 'http://users.example.org/users/3').to_return response({
|
|
100
|
-
stub_request(:get, 'http://users.example.org/users/4').to_return response({
|
|
72
|
+
stub_request(:get, 'http://users.example.org/users/1').to_return response({id: 1, name: 'Anon', age: 12})
|
|
73
|
+
stub_request(:get, 'http://users.example.org/users/2').to_return response({id: 2, name: 'Johnny', age: 42})
|
|
74
|
+
stub_request(:get, 'http://users.example.org/users/3').to_return response({id: 3, type: 'Customer', name: 'Anon', age: 12})
|
|
75
|
+
stub_request(:get, 'http://users.example.org/users/4').to_return response({id: 4, name: 'Johnny', age: 42})
|
|
101
76
|
end
|
|
102
77
|
|
|
103
78
|
context 'with successful response' do
|
|
@@ -106,12 +81,12 @@ describe Acfs::Model::QueryMethods do
|
|
|
106
81
|
Acfs.run
|
|
107
82
|
|
|
108
83
|
expect(users.size).to be == 2
|
|
109
|
-
expect(users[0].attributes).to be == {
|
|
110
|
-
expect(users[1].attributes).to be == {
|
|
84
|
+
expect(users[0].attributes).to be == {id: 1, name: 'Anon', age: 12}.stringify_keys
|
|
85
|
+
expect(users[1].attributes).to be == {id: 2, name: 'Johnny', age: 42}.stringify_keys
|
|
111
86
|
end
|
|
112
87
|
|
|
113
88
|
it 'should invoke callback after all models are loaded' do
|
|
114
|
-
proc = Proc.new {
|
|
89
|
+
proc = Proc.new {}
|
|
115
90
|
expect(proc).to receive(:call) do |users|
|
|
116
91
|
expect(users).to be === @users
|
|
117
92
|
expect(users.size).to be == 2
|
|
@@ -123,8 +98,8 @@ describe Acfs::Model::QueryMethods do
|
|
|
123
98
|
end
|
|
124
99
|
|
|
125
100
|
it 'should invoke multiple callback after all models are loaded' do
|
|
126
|
-
proc1 = Proc.new {
|
|
127
|
-
proc2 = Proc.new {
|
|
101
|
+
proc1 = Proc.new {}
|
|
102
|
+
proc2 = Proc.new {}
|
|
128
103
|
expect(proc1).to receive(:call) do |users|
|
|
129
104
|
expect(users).to be === @users
|
|
130
105
|
expect(users.size).to be == 2
|
|
@@ -152,7 +127,7 @@ describe Acfs::Model::QueryMethods do
|
|
|
152
127
|
|
|
153
128
|
context 'with one 404 response' do
|
|
154
129
|
before do
|
|
155
|
-
stub_request(:get, 'http://users.example.org/users/1').to_return response({
|
|
130
|
+
stub_request(:get, 'http://users.example.org/users/1').to_return response({error: 'not found'}, status: 404)
|
|
156
131
|
end
|
|
157
132
|
|
|
158
133
|
it 'should raise resource not found error' do
|
|
@@ -169,12 +144,12 @@ describe Acfs::Model::QueryMethods do
|
|
|
169
144
|
let(:pc) { PC }
|
|
170
145
|
let(:mac) { Mac }
|
|
171
146
|
before do
|
|
172
|
-
stub_request(:get, 'http://computers.example.org/computers').to_return response([{
|
|
147
|
+
stub_request(:get, 'http://computers.example.org/computers').to_return response([{id: 1, type: 'PC'}, {id: 2, type: 'Computer'}, {id: 3, type: 'Mac'}])
|
|
173
148
|
end
|
|
174
149
|
|
|
175
150
|
it 'should invoke multiple callback after all models are loaded' do
|
|
176
|
-
proc1 = Proc.new {
|
|
177
|
-
proc2 = Proc.new {
|
|
151
|
+
proc1 = Proc.new {}
|
|
152
|
+
proc2 = Proc.new {}
|
|
178
153
|
expect(proc1).to receive(:call) do |computers|
|
|
179
154
|
expect(computers).to be === @computers
|
|
180
155
|
expect(computers.size).to be == 3
|
|
@@ -216,21 +191,21 @@ describe Acfs::Model::QueryMethods do
|
|
|
216
191
|
|
|
217
192
|
context 'with another resource as type instead' do
|
|
218
193
|
before do
|
|
219
|
-
stub_request(:get, 'http://computers.example.org/computers').to_return response([{
|
|
194
|
+
stub_request(:get, 'http://computers.example.org/computers').to_return response([{id: 1, type: 'MyUser'}, {id: 2, type: 'Computer'}, {id: 3, type: 'Mac'}])
|
|
220
195
|
end
|
|
221
196
|
it_behaves_like 'with invalid type'
|
|
222
197
|
end
|
|
223
198
|
|
|
224
199
|
context 'with a random string as type instead' do
|
|
225
200
|
before do
|
|
226
|
-
stub_request(:get, 'http://computers.example.org/computers').to_return response([{
|
|
201
|
+
stub_request(:get, 'http://computers.example.org/computers').to_return response([{id: 1, type: 'PC'}, {id: 2, type: 'noValidType'}, {id: 3, type: 'Mac'}])
|
|
227
202
|
end
|
|
228
203
|
it_behaves_like 'with invalid type'
|
|
229
204
|
end
|
|
230
205
|
|
|
231
206
|
context 'with a non-string as type instead' do
|
|
232
207
|
before do
|
|
233
|
-
stub_request(:get, 'http://computers.example.org/computers').to_return response([{
|
|
208
|
+
stub_request(:get, 'http://computers.example.org/computers').to_return response([{id: 1, type: 'PC'}, {id: 2, type: 'Computer'}, {id: 3, type: 42}])
|
|
234
209
|
end
|
|
235
210
|
it_behaves_like 'with invalid type'
|
|
236
211
|
end
|
|
@@ -264,7 +239,7 @@ describe Acfs::Model::QueryMethods do
|
|
|
264
239
|
before { stub_request(:get, 'http://users.example.org/users?age=24').to_return response([{id: 1, name: 'Mike', age: 24}, {id: 4, type: 'Maria', age: 24}, {id: 7, type: 'James', age: 24}]) }
|
|
265
240
|
|
|
266
241
|
it 'should invoke callback after model is loaded' do
|
|
267
|
-
proc = Proc.new {
|
|
242
|
+
proc = Proc.new {}
|
|
268
243
|
|
|
269
244
|
expect(proc).to receive(:call) do |user|
|
|
270
245
|
expect(user).to eql @user.__getobj__
|
|
@@ -277,8 +252,8 @@ describe Acfs::Model::QueryMethods do
|
|
|
277
252
|
end
|
|
278
253
|
|
|
279
254
|
it 'should invoke multiple callbacks after model is loaded' do
|
|
280
|
-
proc1 = Proc.new {
|
|
281
|
-
proc2 = Proc.new {
|
|
255
|
+
proc1 = Proc.new {}
|
|
256
|
+
proc2 = Proc.new {}
|
|
282
257
|
|
|
283
258
|
expect(proc1).to receive(:call) do |user|
|
|
284
259
|
expect(user).to eql @user.__getobj__
|
|
@@ -307,7 +282,7 @@ describe Acfs::Model::QueryMethods do
|
|
|
307
282
|
let(:model) { Single }
|
|
308
283
|
|
|
309
284
|
it '.find_by should not be defined' do
|
|
310
|
-
expect{ model.find_by }.to raise_error NoMethodError
|
|
285
|
+
expect { model.find_by }.to raise_error NoMethodError
|
|
311
286
|
end
|
|
312
287
|
end
|
|
313
288
|
end
|
|
@@ -317,7 +292,7 @@ describe Acfs::Model::QueryMethods do
|
|
|
317
292
|
it_behaves_like 'find_by'
|
|
318
293
|
|
|
319
294
|
context 'standard resource' do
|
|
320
|
-
let(:model){ MyUser }
|
|
295
|
+
let(:model) { MyUser }
|
|
321
296
|
let!(:user) { model.send described_method, age: 24 }
|
|
322
297
|
subject { Acfs.run; user }
|
|
323
298
|
|
|
@@ -327,7 +302,7 @@ describe Acfs::Model::QueryMethods do
|
|
|
327
302
|
it { should be_nil }
|
|
328
303
|
|
|
329
304
|
it 'should invoke callback after model is loaded' do
|
|
330
|
-
proc = Proc.new {
|
|
305
|
+
proc = Proc.new {}
|
|
331
306
|
|
|
332
307
|
expect(proc).to receive(:call) do |user|
|
|
333
308
|
expect(user).to eql @user.__getobj__
|
|
@@ -339,8 +314,8 @@ describe Acfs::Model::QueryMethods do
|
|
|
339
314
|
end
|
|
340
315
|
|
|
341
316
|
it 'should invoke multiple callbacks after model is loaded' do
|
|
342
|
-
proc1 = Proc.new {
|
|
343
|
-
proc2 = Proc.new {
|
|
317
|
+
proc1 = Proc.new {}
|
|
318
|
+
proc2 = Proc.new {}
|
|
344
319
|
|
|
345
320
|
expect(proc1).to receive(:call) do |user|
|
|
346
321
|
expect(user).to eql @user.__getobj__
|
|
@@ -364,7 +339,7 @@ describe Acfs::Model::QueryMethods do
|
|
|
364
339
|
it_behaves_like 'find_by'
|
|
365
340
|
|
|
366
341
|
context 'standard resource' do
|
|
367
|
-
let(:model){ MyUser }
|
|
342
|
+
let(:model) { MyUser }
|
|
368
343
|
let!(:user) { model.send described_method, age: 24 }
|
|
369
344
|
subject { Acfs.run; user }
|
|
370
345
|
|
|
@@ -373,16 +348,16 @@ describe Acfs::Model::QueryMethods do
|
|
|
373
348
|
|
|
374
349
|
it 'should raise an ResourceNotFound error' do
|
|
375
350
|
model.find_by! age: 24
|
|
376
|
-
expect{ Acfs.run }.to raise_error Acfs::ResourceNotFound
|
|
351
|
+
expect { Acfs.run }.to raise_error Acfs::ResourceNotFound
|
|
377
352
|
end
|
|
378
353
|
|
|
379
354
|
it 'should not invoke callback after model could not be loaded' do
|
|
380
|
-
proc = Proc.new {
|
|
355
|
+
proc = Proc.new {}
|
|
381
356
|
|
|
382
357
|
expect(proc).not_to receive(:call)
|
|
383
358
|
|
|
384
359
|
model.find_by! age: 24, &proc
|
|
385
|
-
expect{ Acfs.run }.to raise_error
|
|
360
|
+
expect { Acfs.run }.to raise_error
|
|
386
361
|
end
|
|
387
362
|
end
|
|
388
363
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Acfs::SingletonResource do
|
|
4
|
+
let(:model) { Single }
|
|
5
|
+
|
|
6
|
+
describe '.find' do
|
|
7
|
+
before do
|
|
8
|
+
stub_request(:get, 'http://users.example.org/singles').to_return response({id:1})
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
let(:action) { lambda{|cb| model.find &cb }}
|
|
12
|
+
it_should_behave_like 'a query method with multi-callback support'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
data/spec/acfs/stub_spec.rb
CHANGED
|
@@ -154,6 +154,20 @@ describe Acfs::Stub do
|
|
|
154
154
|
expect(computers.last).to be_a Mac
|
|
155
155
|
end
|
|
156
156
|
end
|
|
157
|
+
|
|
158
|
+
context 'with header' do
|
|
159
|
+
before do
|
|
160
|
+
Acfs::Stub.resource Comment, :list,
|
|
161
|
+
return: [{ id: 1, text: 'Foo' }, { id: 2, text: 'Bar' }],
|
|
162
|
+
headers: headers
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
let!(:comments) { Comment.all }
|
|
166
|
+
let(:headers) { {'X-Total-Pages' => '2'} }
|
|
167
|
+
subject { Acfs.run; comments }
|
|
168
|
+
|
|
169
|
+
its(:total_pages) { should eq 2 }
|
|
170
|
+
end
|
|
157
171
|
end
|
|
158
172
|
|
|
159
173
|
context 'with update action' do
|
data/spec/spec_helper.rb
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
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 { |cb|
|
|
6
|
+
action.call cb
|
|
7
|
+
Acfs.run
|
|
8
|
+
}.to yield_with_args
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'should invoke multiple callbacks' do
|
|
12
|
+
expect { |cb|
|
|
13
|
+
object = action.call cb
|
|
14
|
+
Acfs.add_callback object, &cb
|
|
15
|
+
Acfs.run
|
|
16
|
+
}.to yield_control.exactly(2).times
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe 'callback' do
|
|
20
|
+
it 'should be invoked with resource' do
|
|
21
|
+
proc = Proc.new { }
|
|
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.new { }
|
|
33
|
+
proc2 = Proc.new { }
|
|
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
|
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: 0.
|
|
4
|
+
version: 0.34.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: 2014-
|
|
11
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -124,6 +124,7 @@ files:
|
|
|
124
124
|
- lib/acfs/adapter/base.rb
|
|
125
125
|
- lib/acfs/adapter/typhoeus.rb
|
|
126
126
|
- lib/acfs/collection.rb
|
|
127
|
+
- lib/acfs/collections/paginatable.rb
|
|
127
128
|
- lib/acfs/configuration.rb
|
|
128
129
|
- lib/acfs/errors.rb
|
|
129
130
|
- lib/acfs/global.rb
|
|
@@ -156,6 +157,7 @@ files:
|
|
|
156
157
|
- lib/acfs/model/service.rb
|
|
157
158
|
- lib/acfs/model/validation.rb
|
|
158
159
|
- lib/acfs/operation.rb
|
|
160
|
+
- lib/acfs/parameter_decoder.rb
|
|
159
161
|
- lib/acfs/request.rb
|
|
160
162
|
- lib/acfs/request/callbacks.rb
|
|
161
163
|
- lib/acfs/resource.rb
|
|
@@ -171,6 +173,7 @@ files:
|
|
|
171
173
|
- lib/acfs/util.rb
|
|
172
174
|
- lib/acfs/version.rb
|
|
173
175
|
- lib/acfs/yard.rb
|
|
176
|
+
- spec/acfs/collection_spec.rb
|
|
174
177
|
- spec/acfs/configuration_spec.rb
|
|
175
178
|
- spec/acfs/middleware/json_decoder_spec.rb
|
|
176
179
|
- spec/acfs/middleware/msgpack_decoder_spec.rb
|
|
@@ -193,12 +196,14 @@ files:
|
|
|
193
196
|
- spec/acfs/response/status_spec.rb
|
|
194
197
|
- spec/acfs/service/middleware_spec.rb
|
|
195
198
|
- spec/acfs/service_spec.rb
|
|
199
|
+
- spec/acfs/singleton_resource_spec.rb
|
|
196
200
|
- spec/acfs/stub_spec.rb
|
|
197
201
|
- spec/acfs_spec.rb
|
|
198
202
|
- spec/fixtures/config.yml
|
|
199
203
|
- spec/spec_helper.rb
|
|
200
204
|
- spec/support/response.rb
|
|
201
205
|
- spec/support/service.rb
|
|
206
|
+
- spec/support/shared/find_callbacks.rb
|
|
202
207
|
homepage: https://github.com/jgraichen/acfs
|
|
203
208
|
licenses:
|
|
204
209
|
- MIT
|
|
@@ -224,6 +229,7 @@ signing_key:
|
|
|
224
229
|
specification_version: 4
|
|
225
230
|
summary: An abstract API base client for service oriented application.
|
|
226
231
|
test_files:
|
|
232
|
+
- spec/acfs/collection_spec.rb
|
|
227
233
|
- spec/acfs/configuration_spec.rb
|
|
228
234
|
- spec/acfs/middleware/json_decoder_spec.rb
|
|
229
235
|
- spec/acfs/middleware/msgpack_decoder_spec.rb
|
|
@@ -246,10 +252,12 @@ test_files:
|
|
|
246
252
|
- spec/acfs/response/status_spec.rb
|
|
247
253
|
- spec/acfs/service/middleware_spec.rb
|
|
248
254
|
- spec/acfs/service_spec.rb
|
|
255
|
+
- spec/acfs/singleton_resource_spec.rb
|
|
249
256
|
- spec/acfs/stub_spec.rb
|
|
250
257
|
- spec/acfs_spec.rb
|
|
251
258
|
- spec/fixtures/config.yml
|
|
252
259
|
- spec/spec_helper.rb
|
|
253
260
|
- spec/support/response.rb
|
|
254
261
|
- spec/support/service.rb
|
|
262
|
+
- spec/support/shared/find_callbacks.rb
|
|
255
263
|
has_rdoc:
|