acfs 0.42.0 → 0.43.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/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
@@ -5,16 +5,16 @@ describe Acfs::Adapter::Typhoeus do
|
|
5
5
|
before { WebMock.allow_net_connect! }
|
6
6
|
|
7
7
|
it 'raises an error' do
|
8
|
-
request1 = Acfs::Request.new 'http://altimos.de/404.1' do |
|
8
|
+
request1 = Acfs::Request.new 'http://altimos.de/404.1' do |_rsp|
|
9
9
|
raise '404-1'
|
10
10
|
end
|
11
|
-
request2 = Acfs::Request.new 'http://altimos.de/404.2' do |
|
11
|
+
request2 = Acfs::Request.new 'http://altimos.de/404.2' do |_rsp|
|
12
12
|
raise '404-2'
|
13
13
|
end
|
14
14
|
adapter.queue request1
|
15
15
|
adapter.queue request2
|
16
16
|
|
17
|
-
expect{ adapter.start }.to raise_error
|
18
|
-
expect{ adapter.start }.to_not raise_error
|
17
|
+
expect { adapter.start }.to raise_error(/404\-[12]/)
|
18
|
+
expect { adapter.start }.to_not raise_error
|
19
19
|
end
|
20
20
|
end
|
@@ -11,9 +11,9 @@ describe Acfs::Collection do
|
|
11
11
|
|
12
12
|
context 'without explicit page parameter' do
|
13
13
|
before do
|
14
|
-
stub_request(:get, 'http://users.example.org/users')
|
15
|
-
|
16
|
-
|
14
|
+
stub_request(:get, 'http://users.example.org/users')
|
15
|
+
.to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
|
16
|
+
headers: {'X-Total-Pages' => '2'})
|
17
17
|
end
|
18
18
|
|
19
19
|
its(:total_pages) { should eq 2 }
|
@@ -23,9 +23,9 @@ describe Acfs::Collection do
|
|
23
23
|
context 'with page parameter' do
|
24
24
|
let(:params) { {page: 2} }
|
25
25
|
before do
|
26
|
-
stub_request(:get, 'http://users.example.org/users?page=2')
|
27
|
-
|
28
|
-
|
26
|
+
stub_request(:get, 'http://users.example.org/users?page=2')
|
27
|
+
.to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
|
28
|
+
headers: {'X-Total-Pages' => '2'})
|
29
29
|
end
|
30
30
|
|
31
31
|
its(:total_pages) { should eq 2 }
|
@@ -35,9 +35,9 @@ describe Acfs::Collection do
|
|
35
35
|
context 'with non-numerical page parameter' do
|
36
36
|
let(:params) { {page: 'e546f5'} }
|
37
37
|
before do
|
38
|
-
stub_request(:get, 'http://users.example.org/users?page=e546f5')
|
39
|
-
|
40
|
-
|
38
|
+
stub_request(:get, 'http://users.example.org/users?page=e546f5')
|
39
|
+
.to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
|
40
|
+
headers: {'X-Total-Pages' => '2'})
|
41
41
|
end
|
42
42
|
|
43
43
|
its(:total_pages) { should eq 2 }
|
@@ -46,12 +46,12 @@ describe Acfs::Collection do
|
|
46
46
|
|
47
47
|
describe '#next_page' do
|
48
48
|
before do
|
49
|
-
stub_request(:get, 'http://users.example.org/users')
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
stub_request(:get, 'http://users.example.org/users')
|
50
|
+
.to_return response([{id: 1, name: 'Anon', age: 12, born_at: 'Berlin'}],
|
51
|
+
headers: {
|
52
|
+
'X-Total-Pages' => '2',
|
53
|
+
'Link' => '<http://users.example.org/users?page=2>; rel="next"'
|
54
|
+
})
|
55
55
|
end
|
56
56
|
let!(:req) do
|
57
57
|
stub_request(:get, 'http://users.example.org/users?page=2').to_return response([])
|
@@ -70,12 +70,12 @@ describe Acfs::Collection do
|
|
70
70
|
|
71
71
|
describe '#prev_page' do
|
72
72
|
before do
|
73
|
-
stub_request(:get, 'http://users.example.org/users?page=2')
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
stub_request(:get, 'http://users.example.org/users?page=2')
|
74
|
+
.to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
75
|
+
headers: {
|
76
|
+
'X-Total-Pages' => '2',
|
77
|
+
'Link' => '<http://users.example.org/users>; rel="prev"'
|
78
|
+
})
|
79
79
|
end
|
80
80
|
let!(:req) do
|
81
81
|
stub_request(:get, 'http://users.example.org/users').to_return response([])
|
@@ -94,12 +94,12 @@ describe Acfs::Collection do
|
|
94
94
|
|
95
95
|
describe '#first_page' do
|
96
96
|
before do
|
97
|
-
stub_request(:get, 'http://users.example.org/users?page=2')
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
stub_request(:get, 'http://users.example.org/users?page=2')
|
98
|
+
.to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
99
|
+
headers: {
|
100
|
+
'X-Total-Pages' => '2',
|
101
|
+
'Link' => '<http://users.example.org/users>; rel="first"'
|
102
|
+
})
|
103
103
|
end
|
104
104
|
let!(:req) do
|
105
105
|
stub_request(:get, 'http://users.example.org/users').to_return response([])
|
@@ -118,12 +118,12 @@ describe Acfs::Collection do
|
|
118
118
|
|
119
119
|
describe '#last_page' do
|
120
120
|
before do
|
121
|
-
stub_request(:get, 'http://users.example.org/users?page=2')
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
121
|
+
stub_request(:get, 'http://users.example.org/users?page=2')
|
122
|
+
.to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
|
123
|
+
headers: {
|
124
|
+
'X-Total-Pages' => '2',
|
125
|
+
'Link' => '<http://users.example.org/users?page=12>; rel="last"'
|
126
|
+
})
|
127
127
|
end
|
128
128
|
let!(:req) do
|
129
129
|
stub_request(:get, 'http://users.example.org/users?page=12').to_return response([])
|
data/spec/acfs/global_spec.rb
CHANGED
@@ -14,11 +14,11 @@ describe ::Acfs::Global do
|
|
14
14
|
let(:adapter) { ::NullAdapter.new }
|
15
15
|
let(:runner) { double 'runner' }
|
16
16
|
let(:collector) { NotificationCollector.new }
|
17
|
-
let(:acfs) { Object.new.tap {
|
17
|
+
let(:acfs) { Object.new.tap {|o| o.extend ::Acfs::Global } }
|
18
18
|
|
19
19
|
describe 'instrumentation' do
|
20
20
|
before do
|
21
|
-
#allow(runner).to receive(:start)
|
21
|
+
# allow(runner).to receive(:start)
|
22
22
|
allow(acfs).to receive(:runner).and_return runner
|
23
23
|
end
|
24
24
|
|
@@ -48,7 +48,7 @@ describe ::Acfs::Global do
|
|
48
48
|
stub_request(:get, %r{http://users.example.org/users/\d+}).to_return(
|
49
49
|
status: 200,
|
50
50
|
body: '{}',
|
51
|
-
headers: {
|
51
|
+
headers: {'Content-Type' => 'application/json'})
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'should invoke when both resources' do
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Middleware::JSON do
|
4
|
-
let(:data) { [{id: 1, name:
|
4
|
+
let(:data) { [{id: 1, name: 'Anon'}, {id: 2, name: 'John', friends: [1]}] }
|
5
5
|
let(:body) { '' }
|
6
6
|
let(:headers) { {} }
|
7
7
|
let(:request) { Acfs::Request.new 'url', method: 'GET', data: data }
|
8
8
|
let(:response) { Acfs::Response.new request, status: 200, headers: headers, body: body }
|
9
|
-
let(:decoder) { Acfs::Middleware::JSON.new
|
9
|
+
let(:decoder) { Acfs::Middleware::JSON.new ->(req) { req } }
|
10
10
|
|
11
11
|
before do
|
12
12
|
decoder.call request
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Middleware::MessagePack do
|
4
|
-
let(:data) { [{id: 1, name: 'Anon'}, {id: 2, name: 'John', friends: [
|
4
|
+
let(:data) { [{id: 1, name: 'Anon'}, {id: 2, name: 'John', friends: [1]}] }
|
5
5
|
let(:body) { '' }
|
6
6
|
let(:headers) { {} }
|
7
7
|
let(:request) { Acfs::Request.new 'url', data: data }
|
8
8
|
let(:response) { Acfs::Response.new request, status: 200, headers: headers, body: body }
|
9
|
-
let(:decoder) { Acfs::Middleware::MessagePack.new ->(req){ req } }
|
9
|
+
let(:decoder) { Acfs::Middleware::MessagePack.new ->(req) { req } }
|
10
10
|
|
11
11
|
before do
|
12
12
|
decoder.call request
|
@@ -43,7 +43,7 @@ describe Acfs::Middleware::MessagePack do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'with Message Pack response' do
|
46
|
-
let(:headers) { {
|
46
|
+
let(:headers) { {'Content-Type' => 'application/x-msgpack'} }
|
47
47
|
let(:body) { MessagePack.pack data }
|
48
48
|
|
49
49
|
it 'should decode body data' do
|
@@ -54,7 +54,7 @@ describe Acfs::Middleware::MessagePack do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
context 'without Message Pack response' do
|
57
|
-
let(:headers) { {
|
57
|
+
let(:headers) { {'Content-Type' => 'application/text'} }
|
58
58
|
let(:body) { data.to_json }
|
59
59
|
|
60
60
|
it 'should not decode non-MessagePack encoded responses' do
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Request::Callbacks do
|
4
|
-
let(:callback) {
|
4
|
+
let(:callback) { ->(_res) {} }
|
5
5
|
let(:request) { Acfs::Request.new('fubar') }
|
6
6
|
|
7
7
|
describe '#on_complete' do
|
8
8
|
it 'should store a given callback' do
|
9
|
-
request.on_complete
|
9
|
+
request.on_complete(&callback)
|
10
10
|
|
11
11
|
expect(request.callbacks).to have(1).item
|
12
12
|
expect(request.callbacks[0]).to be == callback
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should store multiple callback' do
|
16
|
-
request.on_complete {
|
17
|
-
request.on_complete
|
16
|
+
request.on_complete {|_res| 'abc' }
|
17
|
+
request.on_complete(&callback)
|
18
18
|
|
19
19
|
expect(request.callbacks).to have(2).item
|
20
20
|
expect(request.callbacks[0]).to be == callback
|
@@ -27,16 +27,16 @@ describe Acfs::Request::Callbacks do
|
|
27
27
|
it 'should trigger registered callbacks with given response' do
|
28
28
|
expect(callback).to receive(:call).with(response, kind_of(Proc))
|
29
29
|
|
30
|
-
request.on_complete
|
30
|
+
request.on_complete(&callback)
|
31
31
|
request.complete! response
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should trigger multiple callback in reverted insertion order' do
|
35
35
|
check = []
|
36
36
|
|
37
|
-
request.on_complete {
|
38
|
-
request.on_complete {
|
39
|
-
request.on_complete {
|
37
|
+
request.on_complete {|res, nxt| check << 1; nxt.call res }
|
38
|
+
request.on_complete {|res, nxt| check << 2; nxt.call res }
|
39
|
+
request.on_complete {|res, nxt| check << 3; nxt.call res }
|
40
40
|
|
41
41
|
request.complete! response
|
42
42
|
|
data/spec/acfs/request_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Acfs::Request do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'with parameters' do
|
18
|
-
let(:params) { {
|
18
|
+
let(:params) { {id: 10} }
|
19
19
|
|
20
20
|
it 'should return URL without query' do
|
21
21
|
expect(request.url).to be == "#{url}"
|
@@ -24,7 +24,7 @@ describe Acfs::Request do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '#headers' do
|
27
|
-
let(:headers) { {
|
27
|
+
let(:headers) { {'Accept' => 'application/json'} }
|
28
28
|
|
29
29
|
it 'should return request headers' do
|
30
30
|
expect(request.headers).to be == headers
|
@@ -46,7 +46,7 @@ describe Acfs::Request do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
describe '#params' do
|
49
|
-
let(:params) { {
|
49
|
+
let(:params) { {id: 10} }
|
50
50
|
|
51
51
|
it 'should return request headers' do
|
52
52
|
expect(request.params).to be == params
|
@@ -54,7 +54,7 @@ describe Acfs::Request do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
describe '#data' do
|
57
|
-
let(:data) { {
|
57
|
+
let(:data) { {id: 10, name: 'Anon'} }
|
58
58
|
|
59
59
|
it 'should return request data' do
|
60
60
|
expect(request.data).to be == data
|
@@ -63,7 +63,7 @@ describe Acfs::Request do
|
|
63
63
|
|
64
64
|
describe '#data' do
|
65
65
|
context 'with data' do
|
66
|
-
let(:data) { {
|
66
|
+
let(:data) { {id: 10, name: 'Anon'} }
|
67
67
|
|
68
68
|
it { expect(request).to be_data }
|
69
69
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Acfs::
|
4
|
-
subject { Acfs::
|
3
|
+
describe Acfs::Resource::Attributes::Boolean do
|
4
|
+
subject { Acfs::Resource::Attributes::Boolean.new }
|
5
5
|
|
6
6
|
describe 'cast' do
|
7
7
|
it 'should preserve boolean values' do
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Acfs::
|
4
|
-
let(:model) { Class.new
|
3
|
+
describe Acfs::Resource::Attributes::DateTime do
|
4
|
+
let(:model) { Class.new Acfs::Resource }
|
5
5
|
let(:params) { {} }
|
6
|
-
subject { Acfs::
|
6
|
+
subject { Acfs::Resource::Attributes::DateTime.new params }
|
7
7
|
|
8
8
|
describe 'cast' do
|
9
9
|
it 'should return same object, if obj is already of DateTime class' do
|
@@ -32,16 +32,16 @@ describe Acfs::Model::Attributes::DateTime do
|
|
32
32
|
|
33
33
|
it 'should raise an error if obj is of String class not in valid ISO-8601 format' do
|
34
34
|
malformed_string = 'qwe123'
|
35
|
-
expect
|
35
|
+
expect do
|
36
36
|
subject.cast(malformed_string)
|
37
|
-
|
37
|
+
end.to raise_error ArgumentError
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'should raise an error if obj is of wrong class (Fixnum)' do
|
41
41
|
fixnum = 12
|
42
|
-
expect
|
42
|
+
expect do
|
43
43
|
subject.cast(fixnum)
|
44
|
-
|
44
|
+
end.to raise_error TypeError
|
45
45
|
end
|
46
46
|
|
47
47
|
context 'with allow_nil option' do
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Acfs::
|
4
|
-
let(:model) { Class.new
|
5
|
-
subject { Acfs::
|
3
|
+
describe Acfs::Resource::Attributes::Dict do
|
4
|
+
let(:model) { Class.new(Acfs::Resource) }
|
5
|
+
subject { Acfs::Resource::Attributes::Dict.new }
|
6
6
|
|
7
7
|
describe '.cast' do
|
8
8
|
context 'with hash' do
|
9
|
-
let(:sample) { {3 => true,
|
9
|
+
let(:sample) { {3 => true, 'asfd' => 4} }
|
10
10
|
|
11
11
|
it 'should return unmodified hash' do
|
12
12
|
expect(subject.cast(sample)).to be sample
|
@@ -17,9 +17,9 @@ describe Acfs::Model::Attributes::Dict do
|
|
17
17
|
let(:sample) { Object.new }
|
18
18
|
|
19
19
|
it 'should raise a TypeError' do
|
20
|
-
expect
|
20
|
+
expect do
|
21
21
|
subject.cast(sample)
|
22
|
-
|
22
|
+
end.to raise_error TypeError
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Acfs::
|
4
|
-
let(:model) { Class.new
|
5
|
-
subject {
|
3
|
+
describe Acfs::Resource::Attributes::Float do
|
4
|
+
let(:model) { Class.new Acfs::Resource }
|
5
|
+
subject { described_class.new }
|
6
6
|
|
7
7
|
describe 'cast' do
|
8
8
|
it 'should return same object, if obj is already of float class' do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Acfs::
|
4
|
-
let(:model) { Class.new
|
5
|
-
subject {
|
3
|
+
describe Acfs::Resource::Attributes::List do
|
4
|
+
let(:model) { Class.new Acfs::Resource }
|
5
|
+
subject { described_class.new }
|
6
6
|
|
7
7
|
describe '.cast' do
|
8
8
|
context 'with array' do
|
@@ -17,9 +17,9 @@ describe Acfs::Model::Attributes::List do
|
|
17
17
|
let(:sample) { Object.new }
|
18
18
|
|
19
19
|
it 'should raise a TypeError' do
|
20
|
-
expect
|
20
|
+
expect do
|
21
21
|
subject.cast(sample)
|
22
|
-
|
22
|
+
end.to raise_error TypeError
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Acfs::
|
4
|
-
let(:model) { Class.new
|
3
|
+
describe Acfs::Resource::Attributes::UUID do
|
4
|
+
let(:model) { Class.new Acfs::Resource }
|
5
5
|
let(:params) { {} }
|
6
6
|
let(:instance) { described_class.new params }
|
7
7
|
subject { instance }
|
@@ -26,7 +26,7 @@ describe Acfs::Model::Attributes::UUID do
|
|
26
26
|
it { should raise_error ArgumentError }
|
27
27
|
end
|
28
28
|
|
29
|
-
context 'with
|
29
|
+
context 'with UUID string containing invalid characters' do
|
30
30
|
let(:param) { 'xxxxxxxx-yyyy-11e3-baa8-0800200c9a66' }
|
31
31
|
it { should raise_error ArgumentError }
|
32
32
|
end
|
@@ -51,9 +51,9 @@ describe Acfs::Model::Attributes::UUID do
|
|
51
51
|
context 'with non-String as param' do
|
52
52
|
subject { -> { action } }
|
53
53
|
|
54
|
-
invalid_params = {
|
55
|
-
invalid_params.each do |
|
56
|
-
context "with #{
|
54
|
+
invalid_params = {fixnum: 1, float: 3.2, symbol: :invalid, boolean: true}
|
55
|
+
invalid_params.each do |type, incorrect_param|
|
56
|
+
context "with #{type} as param" do
|
57
57
|
let(:param) { incorrect_param }
|
58
58
|
it { should raise_error ArgumentError }
|
59
59
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Acfs::
|
4
|
-
let(:model) { Class.new
|
3
|
+
describe Acfs::Resource::Attributes do
|
4
|
+
let(:model) { Class.new Acfs::Resource }
|
5
5
|
|
6
6
|
describe '#initialize' do
|
7
7
|
before { model.attribute :name, :string, default: 'John' }
|
@@ -33,7 +33,7 @@ describe Acfs::Model::Attributes do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should return hash of all attributes' do
|
36
|
-
expect(model.new.attributes).to
|
36
|
+
expect(model.new.attributes).to eq(name: 'John', age: 25)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -46,15 +46,15 @@ describe Acfs::Model::Attributes do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
let(:args) { [params] }
|
49
|
-
let(:params){ {name: 'James'} }
|
49
|
+
let(:params) { {name: 'James'} }
|
50
50
|
let(:m) { model.new }
|
51
|
-
let(:action) {
|
51
|
+
let(:action) { -> { m.write_attributes(*args) } }
|
52
52
|
subject { action }
|
53
53
|
|
54
54
|
it 'should update attributes' do
|
55
55
|
should change(m, :attributes)
|
56
|
-
|
57
|
-
|
56
|
+
.from(name: 'The Great John', age: 25)
|
57
|
+
.to(name: 'The Great James', age: 25)
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'without non-hash params' do
|
@@ -71,15 +71,24 @@ describe Acfs::Model::Attributes do
|
|
71
71
|
|
72
72
|
it 'should update known attributes and store unknown' do
|
73
73
|
should change(m, :attributes)
|
74
|
-
|
75
|
-
|
74
|
+
.from(name: 'The Great John', age: 25)
|
75
|
+
.to(name: 'The Great James', age: 25, born_at: 'today')
|
76
76
|
end
|
77
77
|
|
78
78
|
context 'with unknown: :raise option' do
|
79
79
|
let(:args) { [params, {unknown: :raise}] }
|
80
80
|
|
81
81
|
it { should raise_error(ArgumentError, /unknown attribute/i) }
|
82
|
-
|
82
|
+
|
83
|
+
it do
|
84
|
+
expect do
|
85
|
+
begin
|
86
|
+
subject.call
|
87
|
+
rescue
|
88
|
+
true
|
89
|
+
end
|
90
|
+
end.to_not change(m, :attributes)
|
91
|
+
end
|
83
92
|
end
|
84
93
|
end
|
85
94
|
end
|
@@ -132,30 +141,33 @@ describe Acfs::Model::Attributes do
|
|
132
141
|
it 'should add an attribute to model attribute list' do
|
133
142
|
model.send :attribute, :name, :string
|
134
143
|
|
135
|
-
expect(model.attributes).to
|
144
|
+
expect(model.attributes.symbolize_keys).to eq name: nil
|
136
145
|
end
|
137
146
|
|
138
147
|
it 'should accept a default value' do
|
139
148
|
model.send :attribute, :name, :string, default: 'John'
|
140
149
|
|
141
|
-
expect(model.attributes).to
|
150
|
+
expect(model.attributes.symbolize_keys).to eq name: 'John'
|
142
151
|
end
|
143
152
|
|
144
153
|
it 'should accept an symbolic type' do
|
145
154
|
model.send :attribute, :age, :integer, default: '12'
|
146
155
|
|
147
|
-
expect(model.attributes).to
|
156
|
+
expect(model.attributes.symbolize_keys).to eq age: 12
|
148
157
|
end
|
149
158
|
|
150
159
|
it 'should accept an class type' do
|
151
|
-
model.send :attribute, :age, Acfs::
|
160
|
+
model.send :attribute, :age, Acfs::Resource::Attributes::Integer,
|
161
|
+
default: '12'
|
152
162
|
|
153
|
-
expect(model.attributes).to
|
163
|
+
expect(model.attributes.symbolize_keys).to eq age: 12
|
154
164
|
end
|
155
165
|
|
156
166
|
context 'allow nil option' do
|
157
167
|
it 'should allow nil as value' do
|
158
|
-
model.send :attribute, :updated_at,
|
168
|
+
model.send :attribute, :updated_at, :date_time,
|
169
|
+
default: DateTime.new, allow_nil: true
|
170
|
+
|
159
171
|
resource = model.new
|
160
172
|
expect(resource.updated_at).to eq DateTime.new
|
161
173
|
|
@@ -166,7 +178,9 @@ describe Acfs::Model::Attributes do
|
|
166
178
|
|
167
179
|
context 'allow blank option' do
|
168
180
|
it 'should allow blank as value' do
|
169
|
-
model.send :attribute, :updated_at,
|
181
|
+
model.send :attribute, :updated_at, :date_time,
|
182
|
+
default: DateTime.new, allow_blank: true
|
183
|
+
|
170
184
|
resource = model.new
|
171
185
|
expect(resource.updated_at).to eq DateTime.new
|
172
186
|
|