acfs 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/README.md +16 -19
  4. data/acfs.gemspec +2 -0
  5. data/lib/acfs/adapter/typhoeus.rb +6 -4
  6. data/lib/acfs/configuration.rb +13 -3
  7. data/lib/acfs/errors.rb +1 -1
  8. data/lib/acfs/global.rb +2 -2
  9. data/lib/acfs/location.rb +1 -1
  10. data/lib/acfs/operation.rb +1 -1
  11. data/lib/acfs/request/callbacks.rb +1 -1
  12. data/lib/acfs/request.rb +1 -1
  13. data/lib/acfs/resource/attributes/uuid.rb +1 -1
  14. data/lib/acfs/resource/locatable.rb +2 -2
  15. data/lib/acfs/resource/query_methods.rb +2 -2
  16. data/lib/acfs/runner.rb +15 -15
  17. data/lib/acfs/stub.rb +34 -29
  18. data/lib/acfs/version.rb +2 -2
  19. data/spec/acfs/adapter/typhoeus_spec.rb +1 -1
  20. data/spec/acfs/collection_spec.rb +66 -41
  21. data/spec/acfs/configuration_spec.rb +22 -12
  22. data/spec/acfs/global_spec.rb +9 -7
  23. data/spec/acfs/middleware/json_spec.rb +8 -8
  24. data/spec/acfs/middleware/{msgpack_spec.rb → message_pack_spec.rb} +6 -6
  25. data/spec/acfs/operation_spec.rb +3 -2
  26. data/spec/acfs/request/callbacks_spec.rb +19 -10
  27. data/spec/acfs/request_spec.rb +15 -19
  28. data/spec/acfs/resource/attributes/boolean_spec.rb +32 -32
  29. data/spec/acfs/resource/attributes/date_time_spec.rb +16 -8
  30. data/spec/acfs/resource/attributes/dict_spec.rb +15 -9
  31. data/spec/acfs/resource/attributes/float_spec.rb +20 -10
  32. data/spec/acfs/resource/attributes/integer_spec.rb +10 -5
  33. data/spec/acfs/resource/attributes/list_spec.rb +13 -8
  34. data/spec/acfs/resource/attributes/uuid_spec.rb +12 -6
  35. data/spec/acfs/resource/attributes_spec.rb +33 -32
  36. data/spec/acfs/resource/dirty_spec.rb +6 -3
  37. data/spec/acfs/resource/initialization_spec.rb +4 -5
  38. data/spec/acfs/resource/loadable_spec.rb +3 -1
  39. data/spec/acfs/resource/locatable_spec.rb +24 -18
  40. data/spec/acfs/resource/{persistance_spec.rb → persistence_spec.rb} +114 -82
  41. data/spec/acfs/resource/query_methods_spec.rb +143 -110
  42. data/spec/acfs/resource/validation_spec.rb +34 -27
  43. data/spec/acfs/response/formats_spec.rb +8 -8
  44. data/spec/acfs/response/status_spec.rb +16 -9
  45. data/spec/acfs/runner_spec.rb +10 -8
  46. data/spec/acfs/service/middleware_spec.rb +3 -3
  47. data/spec/acfs/service_spec.rb +5 -4
  48. data/spec/acfs/singleton_resource_spec.rb +2 -1
  49. data/spec/acfs/stub_spec.rb +57 -53
  50. data/spec/acfs_spec.rb +111 -93
  51. data/spec/spec_helper.rb +1 -1
  52. data/spec/support/response.rb +2 -2
  53. data/spec/support/service.rb +1 -1
  54. data/spec/support/shared/find_callbacks.rb +14 -10
  55. metadata +9 -8
@@ -17,20 +17,19 @@ describe 'Acfs::Resource::Initialization' do
17
17
  end
18
18
 
19
19
  describe '#initialize' do
20
- it 'should allow to set attributes with initializer' do
20
+ it 'allows to set attributes with initializer' do
21
21
  m = model.new name: 'John'
22
22
  expect(m.name).to eq 'John'
23
23
  end
24
24
 
25
- it 'should raise error when attributes with private setters are given' do
25
+ it 'raises error when attributes with private setters are given' do
26
26
  expect { model.new age: 25 }.to raise_error(NoMethodError)
27
27
  end
28
28
  end
29
29
 
30
30
  describe '#persisted?' do
31
- subject { model.new.persisted? }
32
- it 'should be false' do
33
- should be false
31
+ it 'is false' do
32
+ expect(model.new.persisted?).to be false
34
33
  end
35
34
  end
36
35
  end
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe Acfs::Resource::Loadable do
6
6
  let(:model) { MyUser.find 1 }
7
+
7
8
  before do
8
9
  stub_request(:get, 'http://users.example.org/users/1')
9
10
  .to_return response id: 1, name: 'Anon', age: 12
@@ -11,11 +12,12 @@ describe Acfs::Resource::Loadable do
11
12
 
12
13
  describe '#loaded?' do
13
14
  context 'before Acfs#run' do
14
- it { expect(model).to_not be_loaded }
15
+ it { expect(model).not_to be_loaded }
15
16
  end
16
17
 
17
18
  context 'afer Acfs#run' do
18
19
  before { model && Acfs.run }
20
+
19
21
  it { expect(model).to be_loaded }
20
22
  end
21
23
  end
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe Acfs::Resource::Locatable do
6
6
  let(:model) { MyUser }
7
+
7
8
  before do
8
9
  stub_request(:get, 'http://users.example.org/users/1')
9
10
  .to_return response id: 1, name: 'Anon', age: 12
@@ -12,63 +13,67 @@ describe Acfs::Resource::Locatable do
12
13
  end
13
14
 
14
15
  describe '.url' do
15
- it 'should return URL' do
16
- expect(model.url).to be == 'http://users.example.org/users'
16
+ it 'returns URL' do
17
+ expect(model.url).to eq 'http://users.example.org/users'
17
18
  end
18
19
 
19
- it 'should return URL with id path part if specified' do
20
- expect(model.url(5)).to be == 'http://users.example.org/users/5'
20
+ it 'returns URL with id path part if specified' do
21
+ expect(model.url(5)).to eq 'http://users.example.org/users/5'
21
22
  end
22
23
 
23
24
  context 'with attribute in path' do
24
25
  let(:model) { Profile }
25
26
 
26
- it 'should replace placeholder' do
27
+ it 'replaces placeholder' do
27
28
  expect(model.url(user_id: 1))
28
29
  .to eq 'http://users.example.org/users/1/profile'
29
30
  end
30
31
 
31
32
  context 'without attributes' do
32
- it 'should raise an error if attribute is missing' do
33
+ it 'raises an error if attribute is missing' do
33
34
  expect { model.url }.to raise_error ArgumentError
34
35
  end
35
36
  end
36
37
  end
37
38
 
38
39
  describe 'custom paths' do
40
+ subject(:location) { Session.location(action: action) }
41
+
39
42
  let(:model) { Session }
40
- let(:location) { Session.location action: action }
41
- subject { location }
42
43
 
43
44
  context ':list location' do
44
45
  let(:action) { :list }
45
46
 
46
47
  its(:raw_uri) do
47
- should eq 'http://users.example.org/users/:user_id/sessions'
48
+ is_expected.to eq 'http://users.example.org/users/:user_id/sessions'
48
49
  end
49
50
  end
50
51
 
51
52
  context ':create location' do
52
53
  let(:action) { :create }
53
- its(:raw_uri) { should eq 'http://users.example.org/sessions' }
54
+
55
+ its(:raw_uri) { is_expected.to eq 'http://users.example.org/sessions' }
54
56
  end
55
57
 
56
58
  context ':read location' do
57
59
  let(:action) { :read }
58
- its(:raw_uri) { should eq 'http://users.example.org/sessions/:id' }
60
+
61
+ its(:raw_uri) { is_expected.to eq 'http://users.example.org/sessions/:id' }
59
62
  end
60
63
 
61
64
  context ':update location' do
62
65
  let(:action) { :update }
66
+
63
67
  its(:raw_uri) do
64
- expect { subject }.to raise_error ArgumentError, /update.*disabled/
68
+ expect { location }.to raise_error ArgumentError, /update.*disabled/
65
69
  end
66
70
  end
67
71
 
68
72
  context ':delete location' do
69
73
  let(:action) { :delete }
74
+
70
75
  its(:raw_uri) do
71
- should eq 'http://users.example.org/users/:user_id/sessions/del/:id'
76
+ is_expected.to eq 'http://users.example.org/users/:user_id/sessions/del/:id'
72
77
  end
73
78
  end
74
79
  end
@@ -78,20 +83,20 @@ describe Acfs::Resource::Locatable do
78
83
  context 'new resource' do
79
84
  let(:m) { model.new }
80
85
 
81
- it 'should return nil' do
86
+ it 'returns nil' do
82
87
  expect(m.url).to be_nil
83
88
  end
84
89
 
85
90
  context 'new resource with id' do
86
91
  let(:m) { model.new id: 475 }
87
92
 
88
- it 'should return resource URL' do
93
+ it 'returns resource URL' do
89
94
  expect(m.url).to eq 'http://users.example.org/users/475'
90
95
  end
91
96
  end
92
97
 
93
98
  context 'with attribute in path' do
94
- it 'should return nil' do
99
+ it 'returns nil' do
95
100
  expect(m.url).to be_nil
96
101
  end
97
102
  end
@@ -99,9 +104,10 @@ describe Acfs::Resource::Locatable do
99
104
 
100
105
  context 'loaded resource' do
101
106
  let(:m) { model.find 1 }
107
+
102
108
  before { m && Acfs.run }
103
109
 
104
- it "should return resource's URL" do
110
+ it "returns resource's URL" do
105
111
  expect(m.url).to eq 'http://users.example.org/users/1'
106
112
  end
107
113
 
@@ -109,7 +115,7 @@ describe Acfs::Resource::Locatable do
109
115
  let(:model) { Profile }
110
116
  let(:m) { model.find user_id: 1 }
111
117
 
112
- it "should return resource's URL" do
118
+ it "returns resource's URL" do
113
119
  expect(m.url).to eq 'http://users.example.org/users/2/profile'
114
120
  end
115
121
  end
@@ -4,16 +4,28 @@ require 'spec_helper'
4
4
 
5
5
  describe Acfs::Resource::Persistence do
6
6
  let(:model_class) { MyUser }
7
- before do
8
- @get_stub = stub_request(:get, 'http://users.example.org/users/1').to_return response(id: 1, name: 'Anon', age: 12)
9
7
 
10
- @patch_stub = stub_request(:put, 'http://users.example.org/users/1')
11
- .with(body: '{"id":1,"name":"Idefix","age":12}')
12
- .to_return response(id: 1, name: 'Idefix', age: 12)
8
+ let!(:patch_stub) do
9
+ stub_request(:put, 'http://users.example.org/users/1')
10
+ .with(body: '{"id":1,"name":"Idefix","age":12}')
11
+ .to_return response(id: 1, name: 'Idefix', age: 12)
12
+ end
13
13
 
14
- @post_stub = stub_request(:post, 'http://users.example.org/users')
15
- .with(body: '{"id":null,"name":"Idefix","age":12}')
16
- .to_return response(id: 5, name: 'Idefix', age: 12)
14
+ let!(:post_stub) do
15
+ stub_request(:post, 'http://users.example.org/users')
16
+ .with(body: '{"id":null,"name":"Idefix","age":12}')
17
+ .to_return response(id: 5, name: 'Idefix', age: 12)
18
+ end
19
+
20
+ let!(:delete_stub) do
21
+ stub_request(:delete, 'http://users.example.org/users/1')
22
+ .with(body: '{}')
23
+ .to_return response({id: 1, name: 'Idefix', age: 12}, {status: 200})
24
+ end
25
+
26
+ before do
27
+ stub_request(:get, 'http://users.example.org/users/1')
28
+ .to_return response(id: 1, name: 'Anon', age: 12)
17
29
 
18
30
  stub_request(:post, 'http://users.example.org/users')
19
31
  .with(body: '{"id":null,"name":"Anon","age":null}')
@@ -26,41 +38,38 @@ describe Acfs::Resource::Persistence do
26
38
  stub_request(:post, 'http://users.example.org/users')
27
39
  .with(body: '{"id":null,"name":null,"age":12}')
28
40
  .to_return response({errors: {name: ['required']}}, {status: 422})
29
-
30
- @del = stub_request(:delete, 'http://users.example.org/users/1')
31
- .with(body: '{}')
32
- .to_return response({id: 1, name: 'Idefix', age: 12}, {status: 200})
33
41
  end
34
42
 
35
43
  context 'new model' do
36
44
  let(:model) { model_class.new }
37
45
 
38
- it { expect(model).to_not be_persisted }
46
+ it { expect(model).not_to be_persisted }
39
47
  it { expect(model).to be_new }
40
48
 
41
49
  describe '#save!' do
42
50
  context 'when modified' do
43
51
  let(:model) { model_class.find 1 }
52
+
44
53
  before do
45
54
  model
46
55
  Acfs.run
47
56
  model.name = 'Idefix'
48
57
  end
49
58
 
50
- it 'should PUT to model URL' do
59
+ it 'PUTS to model URL' do
51
60
  model.save!
52
61
 
53
- expect(@patch_stub).to have_been_requested
62
+ expect(patch_stub).to have_been_requested
54
63
  end
55
64
  end
56
65
 
57
66
  context 'when new' do
58
67
  let(:model) { model_class.new name: 'Idefix', age: 12 }
59
68
 
60
- it 'should POST to collection URL' do
69
+ it 'POSTS to collection URL' do
61
70
  model.save!
62
71
 
63
- expect(@post_stub).to have_been_requested
72
+ expect(post_stub).to have_been_requested
64
73
  end
65
74
 
66
75
  context 'with unknown attributes' do
@@ -71,17 +80,17 @@ describe Acfs::Resource::Persistence do
71
80
  end
72
81
  let(:model) { model_class.new name: 'Idefix', born_at: 'Berlin' }
73
82
 
74
- it 'should POST to collection URL' do
83
+ it 'POSTS to collection URL' do
75
84
  model.save!
76
85
  expect(req).to have_been_requested
77
86
  end
78
87
 
79
- it 'should still have unknown attribute' do
88
+ it 'stills have unknown attribute' do
80
89
  model.save!
81
90
  expect(model.attributes).to include 'born_at' => 'Berlin'
82
91
  end
83
92
 
84
- it 'should include server send unknown attribute' do
93
+ it 'includes server send unknown attribute' do
85
94
  model.save!
86
95
  expect(model.attributes).to include 'wuff' => 'woa'
87
96
  end
@@ -93,7 +102,7 @@ describe Acfs::Resource::Persistence do
93
102
  before { model.save! }
94
103
 
95
104
  it { expect(model).to be_persisted }
96
- it { expect(model).to_not be_new }
105
+ it { expect(model).not_to be_new }
97
106
  end
98
107
  end
99
108
 
@@ -101,46 +110,63 @@ describe Acfs::Resource::Persistence do
101
110
  let!(:model) { model_class.find 1 }
102
111
 
103
112
  describe '#update_attributes' do
104
- subject { -> { model.update_attributes({name: 'John'}) } }
105
- it { expect { subject.call }.to raise_error Acfs::ResourceNotLoaded }
113
+ it 'to raise error' do
114
+ expect do
115
+ model.update_attributes({name: 'John'})
116
+ end.to raise_error Acfs::ResourceNotLoaded
117
+ end
106
118
  end
107
119
 
108
120
  describe '#update_attributes!' do
109
- subject { -> { model.update_attributes!({name: 'John'}) } }
110
- it { expect { subject.call }.to raise_error Acfs::ResourceNotLoaded }
121
+ it 'to raise error' do
122
+ expect do
123
+ model.update_attributes!({name: 'John'})
124
+ end.to raise_error Acfs::ResourceNotLoaded
125
+ end
111
126
  end
112
127
  end
113
128
 
114
129
  context 'loaded model' do
115
130
  context 'without changes' do
116
131
  let(:model) { model_class.find 1 }
117
- before { model; Acfs.run }
132
+
133
+ before do
134
+ model
135
+ Acfs.run
136
+ end
118
137
 
119
138
  it { expect(model).to be_persisted }
120
- it { expect(model).to_not be_new }
139
+ it { expect(model).not_to be_new }
121
140
  end
122
141
 
123
142
  context 'with changes' do
124
143
  let(:model) { model_class.find 1 }
125
- before { model; Acfs.run; model.name = 'dhh' }
144
+
145
+ before do
146
+ model
147
+ Acfs.run
148
+ model.name = 'dhh'
149
+ end
126
150
 
127
151
  it { expect(model).to be_persisted }
128
- it { expect(model).to_not be_new }
152
+ it { expect(model).not_to be_new }
129
153
  end
130
154
 
131
155
  describe '#delete!' do
132
156
  let(:model) { model_class.find 1 }
133
- let(:before_acfs_run) {}
134
157
 
135
158
  describe 'normal delete actions' do
136
- before { model; Acfs.run }
159
+ before do
160
+ model
161
+ Acfs.run
162
+ end
137
163
 
138
- it 'should trigger DELETE request' do
164
+ it 'triggers DELETE request' do
139
165
  model.delete!
140
- expect(@del).to have_been_requested
166
+ expect(delete_stub).to have_been_requested
141
167
  end
142
168
 
143
- it 'should be frozen after DELETE' do
169
+ it 'is frozen after DELETE' do
144
170
  model.delete!
145
171
  expect(model.__getobj__).to be_frozen
146
172
  end
@@ -149,46 +175,54 @@ describe Acfs::Resource::Persistence do
149
175
  describe 'correct URL generation' do
150
176
  let(:model_class) { PathArguments }
151
177
  let(:model) { model_class.find 1, params: {required_arg: 'some_value'} }
178
+ let(:resource_url) { 'http://users.example.org/some_value/users/1' }
179
+
180
+ let!(:delete_stub) do
181
+ stub_request(:delete, resource_url)
182
+ .with(body: '{}')
183
+ .to_return response({id: 1, required_arg: 'some_value'}, {status: 200})
184
+ end
185
+
186
+ before do
187
+ stub_request(:get, resource_url)
188
+ .to_return response(id: 1, required_arg: 'some_value')
152
189
 
153
- before :each do
154
- resource_url = 'http://users.example.org/some_value/users/1'
155
- @my_get_stub = stub_request(:get, resource_url)
156
- .to_return response(id: 1, required_arg: 'some_value')
157
- @my_delete_stub = stub_request(:delete, resource_url)
158
- .with(body: '{}')
159
- .to_return response({id: 1, required_arg: 'some_value'}, {status: 200})
160
190
  model
161
191
  Acfs.run
162
192
  end
163
193
 
164
- it 'should not raise an error on URL generation' do
194
+ it 'does not raise an error on URL generation' do
165
195
  expect do
166
196
  model.delete!
167
197
  end.not_to raise_error
168
198
  end
169
199
 
170
- it 'should request the delete' do
200
+ it 'requests the delete' do
171
201
  model.delete!
172
- expect(@my_delete_stub).to have_been_requested
202
+ expect(delete_stub).to have_been_requested
173
203
  end
174
204
  end
175
205
  end
176
206
 
177
207
  describe '#update_atributes!' do
178
208
  let(:model) { model_class.find 1 }
179
- before { model; Acfs.run }
180
209
 
181
- it 'should set attributes' do
210
+ before do
211
+ model
212
+ Acfs.run
213
+ end
214
+
215
+ it 'sets attributes' do
182
216
  model.update_attributes({name: 'Idefix'})
183
217
  expect(model.attributes.symbolize_keys).to eq id: 1, name: 'Idefix', age: 12
184
218
  end
185
219
 
186
- it 'should save resource' do
220
+ it 'saves resource' do
187
221
  expect(model.__getobj__).to receive(:save)
188
222
  model.update_attributes({name: 'Idefix'})
189
223
  end
190
224
 
191
- it 'should kwargs to save' do
225
+ it 'kwargses to save' do
192
226
  expect(model.__getobj__).to receive(:save).with(bla: 'blub')
193
227
  model.update_attributes({name: 'Idefix'}, bla: 'blub')
194
228
  end
@@ -196,19 +230,23 @@ describe Acfs::Resource::Persistence do
196
230
 
197
231
  describe '#update_atributes' do
198
232
  let(:model) { model_class.find 1 }
199
- before { model; Acfs.run }
200
233
 
201
- it 'should set attributes' do
234
+ before do
235
+ model
236
+ Acfs.run
237
+ end
238
+
239
+ it 'sets attributes' do
202
240
  model.update_attributes!({name: 'Idefix'})
203
241
  expect(model.attributes.symbolize_keys).to eq id: 1, name: 'Idefix', age: 12
204
242
  end
205
243
 
206
- it 'should save resource' do
244
+ it 'saves resource' do
207
245
  expect(model.__getobj__).to receive(:save!)
208
246
  model.update_attributes!({name: 'Idefix'})
209
247
  end
210
248
 
211
- it 'should pass second hash to save' do
249
+ it 'passes second hash to save' do
212
250
  expect(model.__getobj__).to receive(:save!).with(bla: 'blub')
213
251
  model.update_attributes!({name: 'Idefix'}, bla: 'blub')
214
252
  end
@@ -218,7 +256,11 @@ describe Acfs::Resource::Persistence do
218
256
  describe '.save!' do
219
257
  context 'with invalid data validated on server side' do
220
258
  let(:model) { model_class.find 1 }
221
- before { model; Acfs.run }
259
+
260
+ before do
261
+ model
262
+ Acfs.run
263
+ end
222
264
 
223
265
  before do
224
266
  stub_request(:put, 'http://users.example.org/users/1')
@@ -226,7 +268,7 @@ describe Acfs::Resource::Persistence do
226
268
  .to_return response({errors: {name: ['required']}}, {status: 422})
227
269
  end
228
270
 
229
- it 'should set local errors hash' do
271
+ it 'sets local errors hash' do
230
272
  model.name = ''
231
273
  begin
232
274
  model.save!
@@ -236,30 +278,19 @@ describe Acfs::Resource::Persistence do
236
278
  expect(model.errors.to_hash).to be == {name: %w[required]}
237
279
  end
238
280
  end
239
-
240
- context 'hash modification on iteration in ActiveModel when errors on field is nil' do
241
- let(:model) { model_class.find 1 }
242
- before { model; Acfs.run }
243
-
244
- before do
245
- stub_request(:put, 'http://users.example.org/users/1')
246
- .with(body: '{"id":1,"name":"","age":12}')
247
- .to_return response({errors: {name: ['required']}}, {status: 422})
248
- end
249
- end
250
281
  end
251
282
 
252
283
  describe '.create!' do
253
284
  context 'with valid data' do
254
285
  let(:data) { {name: 'Idefix', age: 12} }
255
286
 
256
- it 'should create new resource' do
287
+ it 'creates new resource' do
257
288
  model = model_class.create! data
258
289
  expect(model.name).to be == 'Idefix'
259
290
  expect(model.age).to be == 12
260
291
  end
261
292
 
262
- it 'should be persisted' do
293
+ it 'is persisted' do
263
294
  model = model_class.create! data
264
295
  expect(model).to be_persisted
265
296
  end
@@ -268,7 +299,7 @@ describe Acfs::Resource::Persistence do
268
299
  context 'with invalid data' do
269
300
  let(:data) { {name: nil, age: 12} }
270
301
 
271
- it 'should raise an error' do
302
+ it 'raises an error' do
272
303
  expect { model_class.create! data }.to \
273
304
  raise_error(::Acfs::InvalidResource) do |error|
274
305
  expect(error.errors).to be == {'name' => %w[required]}
@@ -278,44 +309,45 @@ describe Acfs::Resource::Persistence do
278
309
  end
279
310
 
280
311
  describe '.create' do
281
- subject { model_class.create data }
312
+ subject(:model) { model_class.create data }
282
313
 
283
314
  context 'with valid data' do
284
315
  let(:data) { {name: 'Idefix', age: 12} }
285
316
 
286
- it 'should create new resource' do
287
- expect(subject.name).to be == 'Idefix'
288
- expect(subject.age).to be == 12
317
+ it 'creates new resource' do
318
+ expect(model.name).to be == 'Idefix'
319
+ expect(model.age).to be == 12
289
320
  end
290
321
 
291
- it 'should be persisted' do
292
- expect(subject).to be_persisted
322
+ it 'is persisted' do
323
+ expect(model).to be_persisted
293
324
  end
294
325
  end
295
326
 
296
327
  context 'with invalid data' do
297
328
  let(:data) { {name: nil, age: 12} }
298
329
 
299
- it 'should return not persisted resource' do
300
- expect(subject).to_not be_persisted
330
+ it 'returns not persisted resource' do
331
+ expect(model).not_to be_persisted
301
332
  end
302
333
 
303
- it 'should contain error hash' do
304
- expect(subject.errors.to_hash).to eq name: %w[required]
334
+ it 'contains error hash' do
335
+ expect(model.errors.to_hash).to eq name: %w[required]
305
336
  end
306
337
  end
307
338
 
308
339
  context 'with additional data' do
309
- let!(:req) do
340
+ before do
310
341
  stub_request(:post, 'http://users.example.org/users')
311
342
  .with(body: '{"id":null,"name":"Anon","age":9,"born_at":"today"}')
312
343
  .to_return response(id: 5, name: 'Anon', age: 9)
313
344
  end
345
+
314
346
  let(:data) { {age: 9, born_at: 'today'} }
315
347
 
316
- it 'should store them in attributes' do
317
- expect(subject.attributes).to eq 'id' => 5, 'name' => 'Anon',
318
- 'age' => 9, 'born_at' => 'today'
348
+ it 'stores them in attributes' do
349
+ expect(model.attributes).to eq 'id' => 5, 'name' => 'Anon',
350
+ 'age' => 9, 'born_at' => 'today'
319
351
  end
320
352
  end
321
353
  end