acfs 0.50.0 → 1.0.0.dev.1.b297
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 +13 -5
- data/CHANGELOG.md +0 -80
- data/README.md +9 -8
- data/acfs.gemspec +7 -7
- data/lib/acfs.rb +5 -7
- data/lib/acfs/adapter/base.rb +2 -0
- data/lib/acfs/adapter/typhoeus.rb +13 -17
- data/lib/acfs/collections/paginatable.rb +10 -10
- data/lib/acfs/configuration.rb +5 -4
- data/lib/acfs/errors.rb +9 -10
- data/lib/acfs/global.rb +7 -16
- data/lib/acfs/location.rb +11 -11
- data/lib/acfs/middleware/base.rb +2 -1
- data/lib/acfs/middleware/json_decoder.rb +16 -0
- data/lib/acfs/middleware/json_encoder.rb +20 -0
- data/lib/acfs/middleware/logger.rb +2 -0
- data/lib/acfs/middleware/msgpack_decoder.rb +26 -0
- data/lib/acfs/middleware/msgpack_encoder.rb +19 -0
- data/lib/acfs/middleware/print.rb +2 -0
- data/lib/acfs/operation.rb +5 -5
- data/lib/acfs/request.rb +4 -4
- data/lib/acfs/request/callbacks.rb +3 -2
- data/lib/acfs/resource.rb +2 -2
- data/lib/acfs/resource/attributes.rb +38 -11
- data/lib/acfs/resource/attributes/base.rb +19 -10
- data/lib/acfs/resource/attributes/boolean.rb +8 -10
- data/lib/acfs/resource/attributes/date_time.rb +9 -6
- data/lib/acfs/resource/attributes/float.rb +5 -11
- data/lib/acfs/resource/attributes/integer.rb +5 -7
- data/lib/acfs/resource/attributes/list.rb +6 -13
- data/lib/acfs/resource/attributes/string.rb +5 -3
- data/lib/acfs/resource/attributes/uuid.rb +17 -8
- data/lib/acfs/resource/dirty.rb +15 -3
- data/lib/acfs/resource/loadable.rb +1 -0
- data/lib/acfs/resource/locatable.rb +4 -0
- data/lib/acfs/resource/operational.rb +2 -0
- data/lib/acfs/resource/persistence.rb +17 -17
- data/lib/acfs/resource/query_methods.rb +7 -8
- data/lib/acfs/resource/service.rb +2 -0
- data/lib/acfs/resource/validation.rb +4 -4
- data/lib/acfs/response.rb +2 -1
- data/lib/acfs/response/formats.rb +3 -2
- data/lib/acfs/response/status.rb +5 -3
- data/lib/acfs/runner.rb +11 -21
- data/lib/acfs/service.rb +6 -4
- data/lib/acfs/service/middleware.rb +30 -20
- data/lib/acfs/singleton_resource.rb +2 -0
- data/lib/acfs/stub.rb +21 -30
- data/lib/acfs/util.rb +1 -1
- data/lib/acfs/version.rb +4 -6
- data/spec/acfs/adapter/typhoeus_spec.rb +4 -12
- data/spec/acfs/collection_spec.rb +33 -45
- data/spec/acfs/configuration_spec.rb +1 -9
- data/spec/acfs/global_spec.rb +3 -21
- data/spec/acfs/middleware/json_decoder_spec.rb +45 -0
- data/spec/acfs/middleware/msgpack_decoder_spec.rb +36 -0
- data/spec/acfs/request/callbacks_spec.rb +8 -8
- data/spec/acfs/request_spec.rb +5 -5
- data/spec/acfs/resource/attributes/boolean_spec.rb +9 -40
- data/spec/acfs/resource/attributes/date_time_spec.rb +35 -29
- data/spec/acfs/resource/attributes/float_spec.rb +9 -48
- data/spec/acfs/resource/attributes/list_spec.rb +19 -43
- data/spec/acfs/resource/attributes/uuid_spec.rb +54 -31
- data/spec/acfs/resource/attributes_spec.rb +31 -17
- data/spec/acfs/resource/locatable_spec.rb +2 -2
- data/spec/acfs/resource/persistance_spec.rb +34 -65
- data/spec/acfs/resource/query_methods_spec.rb +90 -97
- data/spec/acfs/resource/validation_spec.rb +5 -4
- data/spec/acfs/response/formats_spec.rb +4 -4
- data/spec/acfs/response/status_spec.rb +1 -1
- data/spec/acfs/runner_spec.rb +3 -28
- data/spec/acfs/service/middleware_spec.rb +20 -4
- data/spec/acfs/service_spec.rb +5 -3
- data/spec/acfs/singleton_resource_spec.rb +2 -1
- data/spec/acfs/stub_spec.rb +22 -137
- data/spec/acfs_spec.rb +19 -22
- data/spec/spec_helper.rb +2 -3
- data/spec/support/service.rb +6 -10
- data/spec/support/shared/find_callbacks.rb +7 -7
- metadata +36 -43
- data/lib/acfs/middleware/json.rb +0 -27
- data/lib/acfs/middleware/msgpack.rb +0 -30
- data/lib/acfs/middleware/serializer.rb +0 -39
- data/lib/acfs/resource/attributes/dict.rb +0 -37
- data/lib/acfs/service/middleware/stack.rb +0 -63
- 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/resource/attributes/dict_spec.rb +0 -75
- data/spec/acfs/resource/attributes/integer_spec.rb +0 -34
@@ -1,59 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes::Float do
|
4
|
-
let(:
|
4
|
+
let(:model) { Class.new Acfs::Resource }
|
5
|
+
subject { described_class.new }
|
5
6
|
|
6
|
-
describe '
|
7
|
-
|
8
|
-
|
9
|
-
context 'with nil' do
|
10
|
-
let(:value) { nil }
|
11
|
-
it { expect(subject.call).to eq nil }
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'with blank string (I)' do
|
15
|
-
let(:value) { '' }
|
16
|
-
it { expect(subject.call).to eq 0.0 }
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'with blank string (II)' do
|
20
|
-
let(:value) { " \t" }
|
21
|
-
it { expect(subject.call).to eq 0.0 }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with float' do
|
25
|
-
let(:value) { 1.7 }
|
26
|
-
it { expect(subject.call).to eq 1.7 }
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with Infinity' do
|
30
|
-
let(:value) { 'Infinity' }
|
31
|
-
it { expect(subject.call).to eq ::Float::INFINITY }
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'with -Infinity' do
|
35
|
-
let(:value) { '-Infinity' }
|
36
|
-
it { expect(subject.call).to eq -::Float::INFINITY }
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'with NaN' do
|
40
|
-
let(:value) { 'NaN' }
|
41
|
-
it { expect(subject.call).to be_nan }
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'with fixnum' do
|
45
|
-
let(:value) { 1 }
|
46
|
-
it { expect(subject.call).to eq 1.0 }
|
7
|
+
describe 'cast' do
|
8
|
+
it 'should return same object, if obj is already of float class' do
|
9
|
+
expect(subject.cast(1.3)).to be == 1.3
|
47
10
|
end
|
48
11
|
|
49
|
-
|
50
|
-
|
51
|
-
it { expect(subject.call).to eq 1.7 }
|
12
|
+
it 'should return parsed object, if obj is of Fixnum class' do
|
13
|
+
expect(subject.cast(7)).to be == 7.0
|
52
14
|
end
|
53
15
|
|
54
|
-
|
55
|
-
|
56
|
-
it { is_expected.to raise_error ArgumentError }
|
16
|
+
it 'should return parsed object, if obj is of String class containing a float' do
|
17
|
+
expect(subject.cast('1.7')).to be == 1.7
|
57
18
|
end
|
58
19
|
end
|
59
20
|
end
|
@@ -1,58 +1,34 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes::List do
|
4
|
-
let(:
|
5
|
-
|
6
|
-
describe '#cast' do
|
7
|
-
subject { -> { type.cast value } }
|
8
|
-
|
9
|
-
context 'with nil' do
|
10
|
-
let(:value) { nil }
|
11
|
-
it { expect(subject.call).to eq nil }
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'with blank string (I)' do
|
15
|
-
let(:value) { '' }
|
16
|
-
it { expect(subject.call).to eq Array.new }
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'with blank string (II)' do
|
20
|
-
let(:value) { " \t" }
|
21
|
-
it { expect(subject.call).to eq Array.new }
|
22
|
-
end
|
4
|
+
let(:model) { Class.new Acfs::Resource }
|
5
|
+
subject { described_class.new }
|
23
6
|
|
7
|
+
describe '.cast' do
|
24
8
|
context 'with array' do
|
25
|
-
let(:
|
26
|
-
it { expect(subject.call).to eq value }
|
27
|
-
end
|
9
|
+
let(:sample) { %w(abc cde efg) }
|
28
10
|
|
29
|
-
|
30
|
-
|
31
|
-
Class.new do
|
32
|
-
def to_ary
|
33
|
-
[1, 2, 3]
|
34
|
-
end
|
35
|
-
end.new
|
11
|
+
it 'should return unmodified array' do
|
12
|
+
expect(subject.cast(sample)).to be == %w(abc cde efg)
|
36
13
|
end
|
37
|
-
|
38
|
-
it { expect(subject.call).to eq [1, 2, 3] }
|
39
14
|
end
|
40
15
|
|
41
|
-
context 'with
|
42
|
-
let(:
|
43
|
-
Class.new do
|
44
|
-
def to_a
|
45
|
-
[1, 2, 3]
|
46
|
-
end
|
47
|
-
end.new
|
48
|
-
end
|
16
|
+
context 'with not listable object' do
|
17
|
+
let(:sample) { Object.new }
|
49
18
|
|
50
|
-
it
|
19
|
+
it 'should raise a TypeError' do
|
20
|
+
expect do
|
21
|
+
subject.cast(sample)
|
22
|
+
end.to raise_error TypeError
|
23
|
+
end
|
51
24
|
end
|
52
25
|
|
53
|
-
context 'with
|
54
|
-
let(:
|
55
|
-
|
26
|
+
context 'with listable object' do
|
27
|
+
let(:sample) { 5..10 }
|
28
|
+
|
29
|
+
it 'should cast object to array' do
|
30
|
+
expect(subject.cast(sample)).to be == [5, 6, 7, 8, 9, 10]
|
31
|
+
end
|
56
32
|
end
|
57
33
|
end
|
58
34
|
end
|
@@ -1,40 +1,63 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes::UUID do
|
4
|
-
let(:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
let(:model) { Class.new Acfs::Resource }
|
5
|
+
let(:params) { {} }
|
6
|
+
let(:instance) { described_class.new params }
|
7
|
+
subject { instance }
|
8
|
+
|
9
|
+
describe '#cast_type' do
|
10
|
+
let(:param) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
|
11
|
+
let(:action) { instance.cast param }
|
12
|
+
subject { action }
|
13
|
+
|
14
|
+
context 'with String as param' do
|
15
|
+
context 'with valid UUID' do
|
16
|
+
let(:param) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
|
17
|
+
it { should be_a String }
|
18
|
+
it { should eq param }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with invalid UUID' do
|
22
|
+
subject { -> { action } }
|
23
|
+
|
24
|
+
context 'with random non-empty string' do
|
25
|
+
let(:param) { 'invalid string' }
|
26
|
+
it { should raise_error ArgumentError }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with UUID string containing invalid characters' do
|
30
|
+
let(:param) { 'xxxxxxxx-yyyy-11e3-baa8-0800200c9a66' }
|
31
|
+
it { should raise_error ArgumentError }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with empty string' do
|
35
|
+
let(:param) { '' }
|
36
|
+
|
37
|
+
context 'with allow_nil option' do
|
38
|
+
let(:params) { {allow_nil: true} }
|
39
|
+
subject { action }
|
40
|
+
it { should eq nil }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'without allow_nil option' do
|
44
|
+
let(:params) { {allow_nil: false} }
|
45
|
+
it { should raise_error ArgumentError }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
12
49
|
end
|
13
50
|
|
14
|
-
context 'with
|
15
|
-
|
16
|
-
it { expect(subject.call).to eq nil }
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'with blank string' do
|
20
|
-
let(:value) { " \t" }
|
21
|
-
it { expect(subject.call).to eq nil }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with string UUID' do
|
25
|
-
let(:value) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
|
26
|
-
it { expect(subject.call).to be_a String }
|
27
|
-
it { expect(subject.call).to eq value }
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with invalid string' do
|
31
|
-
let(:value) { 'invalid string' }
|
32
|
-
it { is_expected.to raise_error TypeError, /invalid UUID/i }
|
33
|
-
end
|
51
|
+
context 'with non-String as param' do
|
52
|
+
subject { -> { action } }
|
34
53
|
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
+
let(:param) { incorrect_param }
|
58
|
+
it { should raise_error ArgumentError }
|
59
|
+
end
|
60
|
+
end
|
38
61
|
end
|
39
62
|
end
|
40
63
|
end
|
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Acfs::Resource::Attributes do
|
4
4
|
let(:model) { Class.new Acfs::Resource }
|
5
|
-
let(:submodel) { Class.new model }
|
6
5
|
|
7
6
|
describe '#initialize' do
|
8
7
|
before { model.attribute :name, :string, default: 'John' }
|
@@ -47,15 +46,15 @@ describe Acfs::Resource::Attributes do
|
|
47
46
|
end
|
48
47
|
end
|
49
48
|
let(:args) { [params] }
|
50
|
-
let(:params)
|
49
|
+
let(:params){ {name: 'James'} }
|
51
50
|
let(:m) { model.new }
|
52
|
-
let(:action) { ->
|
51
|
+
let(:action) { ->{ m.write_attributes(*args) } }
|
53
52
|
subject { action }
|
54
53
|
|
55
54
|
it 'should update attributes' do
|
56
55
|
should change(m, :attributes)
|
57
|
-
|
58
|
-
|
56
|
+
.from(name: 'The Great John', age: 25)
|
57
|
+
.to(name: 'The Great James', age: 25)
|
59
58
|
end
|
60
59
|
|
61
60
|
context 'without non-hash params' do
|
@@ -72,8 +71,8 @@ describe Acfs::Resource::Attributes do
|
|
72
71
|
|
73
72
|
it 'should update known attributes and store unknown' do
|
74
73
|
should change(m, :attributes)
|
75
|
-
|
76
|
-
|
74
|
+
.from(name: 'The Great John', age: 25)
|
75
|
+
.to(name: 'The Great James', age: 25, born_at: 'today')
|
77
76
|
end
|
78
77
|
|
79
78
|
context 'with unknown: :raise option' do
|
@@ -138,7 +137,7 @@ describe Acfs::Resource::Attributes do
|
|
138
137
|
end
|
139
138
|
|
140
139
|
describe 'class' do
|
141
|
-
describe '#
|
140
|
+
describe '#attribute' do
|
142
141
|
it 'should add an attribute to model attribute list' do
|
143
142
|
model.send :attribute, :name, :string
|
144
143
|
|
@@ -151,27 +150,42 @@ describe Acfs::Resource::Attributes do
|
|
151
150
|
expect(model.attributes.symbolize_keys).to eq name: 'John'
|
152
151
|
end
|
153
152
|
|
154
|
-
it 'should accept
|
153
|
+
it 'should accept an symbolic type' do
|
155
154
|
model.send :attribute, :age, :integer, default: '12'
|
156
155
|
|
157
156
|
expect(model.attributes.symbolize_keys).to eq age: 12
|
158
157
|
end
|
159
158
|
|
160
|
-
it 'should accept
|
159
|
+
it 'should accept an class type' do
|
161
160
|
model.send :attribute, :age, Acfs::Resource::Attributes::Integer,
|
162
|
-
|
161
|
+
default: '12'
|
163
162
|
|
164
163
|
expect(model.attributes.symbolize_keys).to eq age: 12
|
165
164
|
end
|
166
165
|
|
167
|
-
context '
|
168
|
-
|
169
|
-
model.
|
170
|
-
|
166
|
+
context 'allow nil option' do
|
167
|
+
it 'should allow nil as value' do
|
168
|
+
model.send :attribute, :updated_at, :date_time,
|
169
|
+
default: DateTime.new, allow_nil: true
|
170
|
+
|
171
|
+
resource = model.new
|
172
|
+
expect(resource.updated_at).to eq DateTime.new
|
173
|
+
|
174
|
+
resource.updated_at = ''
|
175
|
+
expect(resource.updated_at).to eq nil
|
171
176
|
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'allow blank option' do
|
180
|
+
it 'should allow blank as value' do
|
181
|
+
model.send :attribute, :updated_at, :date_time,
|
182
|
+
default: DateTime.new, allow_blank: true
|
183
|
+
|
184
|
+
resource = model.new
|
185
|
+
expect(resource.updated_at).to eq DateTime.new
|
172
186
|
|
173
|
-
|
174
|
-
expect(
|
187
|
+
resource.updated_at = ''
|
188
|
+
expect(resource.updated_at).to eq nil
|
175
189
|
end
|
176
190
|
end
|
177
191
|
end
|
@@ -28,7 +28,7 @@ describe Acfs::Resource::Locatable do
|
|
28
28
|
|
29
29
|
context 'without attributes' do
|
30
30
|
it 'should raise an error if attribute is missing' do
|
31
|
-
expect
|
31
|
+
expect{ model.url }.to raise_error ArgumentError
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -59,7 +59,7 @@ describe Acfs::Resource::Locatable do
|
|
59
59
|
context ':update location' do
|
60
60
|
let(:action) { :update }
|
61
61
|
its(:raw_uri) do
|
62
|
-
expect
|
62
|
+
expect{ subject }.to raise_error ArgumentError, /update.*disabled/
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -3,31 +3,31 @@ require 'spec_helper'
|
|
3
3
|
describe Acfs::Resource::Persistence do
|
4
4
|
let(:model_class) { MyUser }
|
5
5
|
before do
|
6
|
-
@get_stub = stub_request(:get, 'http://users.example.org/users/1').to_return response(id: 1, name: 'Anon', age: 12)
|
6
|
+
@get_stub = stub_request(:get, 'http://users.example.org/users/1').to_return response({ id: 1, name: 'Anon', age: 12 })
|
7
7
|
|
8
8
|
@patch_stub = stub_request(:put, 'http://users.example.org/users/1')
|
9
|
-
|
10
|
-
|
9
|
+
.with(body: '{"id":1,"name":"Idefix","age":12}')
|
10
|
+
.to_return response({ id: 1, name: 'Idefix', age: 12 })
|
11
11
|
|
12
12
|
@post_stub = stub_request(:post, 'http://users.example.org/users')
|
13
|
-
|
14
|
-
|
13
|
+
.with(body: '{"id":null,"name":"Idefix","age":12}')
|
14
|
+
.to_return response({ id: 5, name: 'Idefix', age: 12 })
|
15
15
|
|
16
16
|
stub_request(:post, 'http://users.example.org/users')
|
17
17
|
.with(body: '{"id":null,"name":"Anon","age":null}')
|
18
|
-
.to_return response(id: 5, name: 'Anon', age: 12)
|
18
|
+
.to_return response({ id: 5, name: 'Anon', age: 12 })
|
19
19
|
|
20
20
|
stub_request(:post, 'http://users.example.org/users')
|
21
21
|
.with(body: '{id:null,"name":"Idefix","age":12}')
|
22
|
-
.to_return response(id: 5, name: 'Idefix', age: 12)
|
22
|
+
.to_return response({ id: 5, name: 'Idefix', age: 12 })
|
23
23
|
|
24
24
|
stub_request(:post, 'http://users.example.org/users')
|
25
25
|
.with(body: '{"id":null,"name":null,"age":12}')
|
26
|
-
.to_return response({errors: {name: ['required']}},
|
26
|
+
.to_return response({ errors: { name: [ 'required' ] }}, status: 422)
|
27
27
|
|
28
28
|
@del = stub_request(:delete, 'http://users.example.org/users/1')
|
29
|
-
|
30
|
-
|
29
|
+
.with(body: '{}')
|
30
|
+
.to_return response({ id: 1, name: 'Idefix', age: 12 }, status: 200)
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'new model' do
|
@@ -65,7 +65,7 @@ describe Acfs::Resource::Persistence do
|
|
65
65
|
let!(:req) do
|
66
66
|
stub_request(:post, 'http://users.example.org/users')
|
67
67
|
.with(body: '{"id":null,"name":"Idefix","age":null,"born_at":"Berlin"}')
|
68
|
-
.to_return response(id: 5, name: 'Idefix', age: 12, wuff: 'woa')
|
68
|
+
.to_return response({id: 5, name: 'Idefix', age: 12, wuff: 'woa'})
|
69
69
|
end
|
70
70
|
let(:model) { model_class.new name: 'Idefix', born_at: 'Berlin' }
|
71
71
|
|
@@ -100,12 +100,12 @@ describe Acfs::Resource::Persistence do
|
|
100
100
|
|
101
101
|
describe '#update_attributes' do
|
102
102
|
subject { -> { model.update_attributes name: 'John' } }
|
103
|
-
it { expect
|
103
|
+
it { expect{ subject.call }.to raise_error Acfs::ResourceNotLoaded }
|
104
104
|
end
|
105
105
|
|
106
106
|
describe '#update_attributes!' do
|
107
107
|
subject { -> { model.update_attributes! name: 'John' } }
|
108
|
-
it { expect
|
108
|
+
it { expect{ subject.call }.to raise_error Acfs::ResourceNotLoaded }
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
@@ -122,53 +122,22 @@ describe Acfs::Resource::Persistence do
|
|
122
122
|
let(:model) { model_class.find 1 }
|
123
123
|
before { model; Acfs.run; model.name = 'dhh' }
|
124
124
|
|
125
|
-
it { expect(model).
|
125
|
+
it { expect(model).to_not be_persisted }
|
126
126
|
it { expect(model).to_not be_new }
|
127
127
|
end
|
128
128
|
|
129
129
|
describe '#delete!' do
|
130
130
|
let(:model) { model_class.find 1 }
|
131
|
-
|
132
|
-
|
133
|
-
describe 'normal delete actions' do
|
134
|
-
before { model; Acfs.run }
|
135
|
-
|
136
|
-
it 'should trigger DELETE request' do
|
137
|
-
model.delete!
|
138
|
-
expect(@del).to have_been_requested
|
139
|
-
end
|
131
|
+
before { model; Acfs.run }
|
140
132
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
133
|
+
it 'should trigger DELETE request' do
|
134
|
+
model.delete!
|
135
|
+
expect(@del).to have_been_requested
|
145
136
|
end
|
146
137
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
before :each do
|
152
|
-
resource_url = 'http://users.example.org/some_value/users/1'
|
153
|
-
@my_get_stub = stub_request(:get, resource_url)
|
154
|
-
.to_return response(id: 1, required_arg: 'some_value')
|
155
|
-
@my_delete_stub = stub_request(:delete, resource_url)
|
156
|
-
.with(body: '{}')
|
157
|
-
.to_return response({id: 1, required_arg: 'some_value'}, {status: 200})
|
158
|
-
model
|
159
|
-
Acfs.run
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'should not raise an error on URL generation' do
|
163
|
-
expect do
|
164
|
-
model.delete!
|
165
|
-
end.not_to raise_error
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'should request the delete' do
|
169
|
-
model.delete!
|
170
|
-
expect(@my_delete_stub).to have_been_requested
|
171
|
-
end
|
138
|
+
it 'should be frozen after DELETE' do
|
139
|
+
model.delete!
|
140
|
+
expect(model.__getobj__).to be_frozen
|
172
141
|
end
|
173
142
|
end
|
174
143
|
|
@@ -187,8 +156,8 @@ describe Acfs::Resource::Persistence do
|
|
187
156
|
end
|
188
157
|
|
189
158
|
it 'should pass second hash to save' do
|
190
|
-
expect(model.__getobj__).to receive(:save).with(bla: 'blub')
|
191
|
-
model.update_attributes({name: 'Idefix'}, {bla: 'blub'})
|
159
|
+
expect(model.__getobj__).to receive(:save).with({ bla: 'blub' })
|
160
|
+
model.update_attributes({ name: 'Idefix' }, { bla: 'blub' })
|
192
161
|
end
|
193
162
|
end
|
194
163
|
|
@@ -207,8 +176,8 @@ describe Acfs::Resource::Persistence do
|
|
207
176
|
end
|
208
177
|
|
209
178
|
it 'should pass second hash to save' do
|
210
|
-
expect(model.__getobj__).to receive(:save!).with(bla: 'blub')
|
211
|
-
model.update_attributes!({name: 'Idefix'}, {bla: 'blub'})
|
179
|
+
expect(model.__getobj__).to receive(:save!).with({ bla: 'blub' })
|
180
|
+
model.update_attributes!({ name: 'Idefix' }, { bla: 'blub' })
|
212
181
|
end
|
213
182
|
end
|
214
183
|
end
|
@@ -221,13 +190,13 @@ describe Acfs::Resource::Persistence do
|
|
221
190
|
before do
|
222
191
|
stub_request(:put, 'http://users.example.org/users/1')
|
223
192
|
.with(body: '{"id":1,"name":"","age":12}')
|
224
|
-
.to_return response({errors: {name: ['required']}},
|
193
|
+
.to_return response({ errors: { name: [ 'required' ] }}, status: 422)
|
225
194
|
end
|
226
195
|
|
227
196
|
it 'should set local errors hash' do
|
228
197
|
model.name = ''
|
229
198
|
model.save! rescue nil
|
230
|
-
expect(model.errors.to_hash).to be == {name: %w(required)}
|
199
|
+
expect(model.errors.to_hash).to be == { name: %w(required) }
|
231
200
|
end
|
232
201
|
end
|
233
202
|
|
@@ -237,15 +206,15 @@ describe Acfs::Resource::Persistence do
|
|
237
206
|
|
238
207
|
before do
|
239
208
|
stub_request(:put, 'http://users.example.org/users/1')
|
240
|
-
|
241
|
-
|
209
|
+
.with(body: '{"id":1,"name":"","age":12}')
|
210
|
+
.to_return response({ errors: { name: [ 'required' ] }}, status: 422)
|
242
211
|
end
|
243
212
|
end
|
244
213
|
end
|
245
214
|
|
246
215
|
describe '.create!' do
|
247
216
|
context 'with valid data' do
|
248
|
-
let(:data) { {name: 'Idefix', age: 12} }
|
217
|
+
let(:data) { { name: 'Idefix', age: 12 } }
|
249
218
|
|
250
219
|
it 'should create new resource' do
|
251
220
|
model = model_class.create! data
|
@@ -263,9 +232,9 @@ describe Acfs::Resource::Persistence do
|
|
263
232
|
let(:data) { {name: nil, age: 12} }
|
264
233
|
|
265
234
|
it 'should raise an error' do
|
266
|
-
expect
|
235
|
+
expect{ model_class.create! data }.to \
|
267
236
|
raise_error(::Acfs::InvalidResource) do |error|
|
268
|
-
expect(error.errors).to be == {'name' => %w(required)}
|
237
|
+
expect(error.errors).to be == { 'name' => %w(required) }
|
269
238
|
end
|
270
239
|
end
|
271
240
|
end
|
@@ -303,13 +272,13 @@ describe Acfs::Resource::Persistence do
|
|
303
272
|
let!(:req) do
|
304
273
|
stub_request(:post, 'http://users.example.org/users')
|
305
274
|
.with(body: '{"id":null,"name":"Anon","age":9,"born_at":"today"}')
|
306
|
-
.to_return response(id: 5, name: 'Anon', age: 9)
|
275
|
+
.to_return response({id: 5, name: 'Anon', age: 9})
|
307
276
|
end
|
308
277
|
let(:data) { {age: 9, born_at: 'today'} }
|
309
278
|
|
310
279
|
it 'should store them in attributes' do
|
311
280
|
expect(subject.attributes).to eq 'id' => 5, 'name' => 'Anon',
|
312
|
-
|
281
|
+
'age' => 9, 'born_at' => 'today'
|
313
282
|
end
|
314
283
|
end
|
315
284
|
end
|