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