acfs 1.4.0 → 1.7.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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/README.md +22 -39
  4. data/acfs.gemspec +8 -14
  5. data/lib/acfs/adapter/base.rb +2 -0
  6. data/lib/acfs/adapter/typhoeus.rb +16 -11
  7. data/lib/acfs/collections/paginatable.rb +1 -1
  8. data/lib/acfs/configuration.rb +13 -3
  9. data/lib/acfs/errors.rb +41 -21
  10. data/lib/acfs/global.rb +2 -2
  11. data/lib/acfs/location.rb +26 -32
  12. data/lib/acfs/middleware/base.rb +2 -2
  13. data/lib/acfs/middleware/json.rb +4 -2
  14. data/lib/acfs/middleware/logger.rb +4 -6
  15. data/lib/acfs/middleware/serializer.rb +1 -1
  16. data/lib/acfs/operation.rb +21 -8
  17. data/lib/acfs/request/callbacks.rb +4 -4
  18. data/lib/acfs/request.rb +4 -11
  19. data/lib/acfs/resource/attributes/date_time.rb +1 -1
  20. data/lib/acfs/resource/attributes/uuid.rb +1 -1
  21. data/lib/acfs/resource/attributes.rb +16 -15
  22. data/lib/acfs/resource/dirty.rb +2 -2
  23. data/lib/acfs/resource/initialization.rb +5 -5
  24. data/lib/acfs/resource/locatable.rb +11 -8
  25. data/lib/acfs/resource/operational.rb +6 -3
  26. data/lib/acfs/resource/persistence.rb +13 -15
  27. data/lib/acfs/resource/query_methods.rb +10 -10
  28. data/lib/acfs/resource/service.rb +2 -2
  29. data/lib/acfs/resource/validation.rb +17 -7
  30. data/lib/acfs/response.rb +5 -5
  31. data/lib/acfs/runner.rb +15 -15
  32. data/lib/acfs/service.rb +16 -19
  33. data/lib/acfs/singleton_resource.rb +2 -2
  34. data/lib/acfs/stub.rb +41 -31
  35. data/lib/acfs/version.rb +2 -2
  36. data/spec/acfs/adapter/typhoeus_spec.rb +2 -2
  37. data/spec/acfs/collection_spec.rb +66 -41
  38. data/spec/acfs/configuration_spec.rb +22 -12
  39. data/spec/acfs/global_spec.rb +11 -9
  40. data/spec/acfs/location_spec.rb +2 -2
  41. data/spec/acfs/middleware/json_spec.rb +22 -8
  42. data/spec/acfs/middleware/{msgpack_spec.rb → message_pack_spec.rb} +6 -6
  43. data/spec/acfs/operation_spec.rb +3 -2
  44. data/spec/acfs/request/callbacks_spec.rb +19 -10
  45. data/spec/acfs/request_spec.rb +16 -20
  46. data/spec/acfs/resource/attributes/boolean_spec.rb +32 -32
  47. data/spec/acfs/resource/attributes/date_time_spec.rb +16 -8
  48. data/spec/acfs/resource/attributes/dict_spec.rb +15 -9
  49. data/spec/acfs/resource/attributes/float_spec.rb +20 -10
  50. data/spec/acfs/resource/attributes/integer_spec.rb +10 -5
  51. data/spec/acfs/resource/attributes/list_spec.rb +13 -8
  52. data/spec/acfs/resource/attributes/uuid_spec.rb +12 -6
  53. data/spec/acfs/resource/attributes_spec.rb +37 -38
  54. data/spec/acfs/resource/dirty_spec.rb +6 -3
  55. data/spec/acfs/resource/initialization_spec.rb +4 -5
  56. data/spec/acfs/resource/loadable_spec.rb +3 -1
  57. data/spec/acfs/resource/locatable_spec.rb +24 -18
  58. data/spec/acfs/resource/{persistance_spec.rb → persistence_spec.rb} +122 -90
  59. data/spec/acfs/resource/query_methods_spec.rb +143 -110
  60. data/spec/acfs/resource/validation_spec.rb +34 -27
  61. data/spec/acfs/response/formats_spec.rb +8 -8
  62. data/spec/acfs/response/status_spec.rb +16 -9
  63. data/spec/acfs/runner_spec.rb +10 -8
  64. data/spec/acfs/service/middleware_spec.rb +3 -3
  65. data/spec/acfs/service_spec.rb +6 -5
  66. data/spec/acfs/singleton_resource_spec.rb +2 -1
  67. data/spec/acfs/stub_spec.rb +57 -53
  68. data/spec/acfs_spec.rb +111 -93
  69. data/spec/spec_helper.rb +1 -2
  70. data/spec/support/response.rb +2 -2
  71. data/spec/support/service.rb +1 -1
  72. data/spec/support/shared/find_callbacks.rb +14 -10
  73. metadata +30 -29
@@ -7,8 +7,9 @@ class SpecialCustomError < StandardError; end
7
7
  describe Acfs::Stub do
8
8
  let(:stub) { Class.new(Acfs::Stub) }
9
9
 
10
- before(:all) { Acfs::Stub.enable }
11
- after(:all) { Acfs::Stub.disable }
10
+ before(:all) { Acfs::Stub.enable } # rubocop:disable RSpec/BeforeAfterAll
11
+
12
+ after(:all) { Acfs::Stub.disable } # rubocop:disable RSpec/BeforeAfterAll
12
13
 
13
14
  before do
14
15
  Acfs::Stub.allow_requests = false
@@ -16,16 +17,18 @@ describe Acfs::Stub do
16
17
 
17
18
  describe '#called?' do
18
19
  context 'without specified number' do
19
- let!(:operation) { Acfs::Stub.resource MyUser, :read, with: {id: 1}, return: {id: 1, name: 'John Smith', age: 32} }
20
+ let!(:operation) do
21
+ Acfs::Stub.resource MyUser, :read, with: {id: 1}, return: {id: 1, name: 'John Smith', age: 32}
22
+ end
20
23
 
21
- it 'should allow to test if stub was called' do
24
+ it 'allows to test if stub was called' do
22
25
  MyUser.find 1
23
26
  Acfs.run
24
27
 
25
28
  expect(operation).to be_called
26
29
  end
27
30
 
28
- it 'should allow to test if stub was called a specific number of times' do
31
+ it 'allows to test if stub was called a specific number of times' do
29
32
  MyUser.find 1
30
33
  Acfs.run
31
34
 
@@ -44,7 +47,7 @@ describe Acfs::Stub do
44
47
  Acfs::Stub.resource MyUser, :read, with: {id: 1}, raise: :not_found
45
48
  end
46
49
 
47
- it 'should raise error' do
50
+ it 'raises error' do
48
51
  MyUser.find 1
49
52
 
50
53
  expect { Acfs.run }.to raise_error(Acfs::AmbiguousStubError)
@@ -58,23 +61,23 @@ describe Acfs::Stub do
58
61
  Acfs::Stub.resource MyUser, :read, with: {id: 3}, raise: :not_found
59
62
  end
60
63
 
61
- it 'should allow to stub resource reads' do
64
+ it 'allows to stub resource reads' do
62
65
  user = MyUser.find 1
63
66
  Acfs.run
64
67
 
65
- expect(user.id).to be == 1
66
- expect(user.name).to be == 'John Smith'
67
- expect(user.age).to be == 32
68
+ expect(user.id).to eq 1
69
+ expect(user.name).to eq 'John Smith'
70
+ expect(user.age).to eq 32
68
71
  end
69
72
 
70
73
  context 'with error' do
71
- it 'should allow to raise errors' do
74
+ it 'allows to raise errors' do
72
75
  MyUser.find 2
73
76
 
74
77
  expect { Acfs.run }.to raise_error(SpecialCustomError)
75
78
  end
76
79
 
77
- it 'should allow to raise symbolic errors' do
80
+ it 'allows to raise symbolic errors' do
78
81
  MyUser.find 3
79
82
 
80
83
  expect { Acfs.run }.to raise_error(Acfs::ResourceNotFound)
@@ -87,7 +90,7 @@ describe Acfs::Stub do
87
90
  Acfs::Stub.resource Computer, :read, with: {id: 2}, return: {id: 2, type: 'Mac'}
88
91
  end
89
92
 
90
- it 'should create inherited type' do
93
+ it 'creates inherited type' do
91
94
  pc = Computer.find 1
92
95
  mac = Computer.find 2
93
96
 
@@ -101,18 +104,26 @@ describe Acfs::Stub do
101
104
 
102
105
  context 'with create action' do
103
106
  before do
104
- Acfs::Stub.resource Session, :create, with: {ident: 'john@exmaple.org', password: 's3cr3t'}, return: {id: 'longhash', user: 1}
105
- Acfs::Stub.resource Session, :create, with: ->(op) { op.data[:ident] == 'john@exmaple.org' && op.data[:password] == 'wrong' }, raise: 422
107
+ lmbd = lambda {|op|
108
+ op.data[:ident] == 'john@exmaple.org' && op.data[:password] == 'wrong'
109
+ }
110
+
111
+ Acfs::Stub.resource Session, :create,
112
+ with: {ident: 'john@exmaple.org', password: 's3cr3t'},
113
+ return: {id: 'longhash', user: 1}
114
+ Acfs::Stub.resource Session, :create,
115
+ with: lmbd,
116
+ raise: 422
106
117
  end
107
118
 
108
- it 'should allow stub resource creation' do
119
+ it 'allows stub resource creation' do
109
120
  session = Session.create! ident: 'john@exmaple.org', password: 's3cr3t'
110
121
 
111
- expect(session.id).to be == 'longhash'
112
- expect(session.user).to be == 1
122
+ expect(session.id).to eq 'longhash'
123
+ expect(session.user).to eq 1
113
124
  end
114
125
 
115
- it 'should allow to raise error' do
126
+ it 'allows to raise error' do
116
127
  expect do
117
128
  Session.create! ident: 'john@exmaple.org', password: 'wrong'
118
129
  end.to raise_error(::Acfs::InvalidResource)
@@ -125,14 +136,14 @@ describe Acfs::Stub do
125
136
  return: [{id: 1, name: 'John Smith', age: 32}, {id: 2, name: 'Anon', age: 12}]
126
137
  end
127
138
 
128
- it 'should return collection' do
139
+ it 'returns collection' do
129
140
  users = MyUser.all
130
141
  Acfs.run
131
142
 
132
143
  expect(users).to have(2).items
133
144
  end
134
145
 
135
- it 'should return defined resources' do
146
+ it 'returns defined resources' do
136
147
  users = MyUser.all
137
148
  Acfs.run
138
149
 
@@ -148,7 +159,7 @@ describe Acfs::Stub do
148
159
  return: [{id: 1, type: 'PC'}, {id: 2, type: 'Mac'}]
149
160
  end
150
161
 
151
- it 'should create inherited type' do
162
+ it 'creates inherited type' do
152
163
  computers = Computer.all
153
164
  Acfs.run
154
165
 
@@ -158,6 +169,11 @@ describe Acfs::Stub do
158
169
  end
159
170
 
160
171
  context 'with header' do
172
+ subject do
173
+ Acfs.run
174
+ comments
175
+ end
176
+
161
177
  before do
162
178
  Acfs::Stub.resource Comment, :list,
163
179
  return: [{id: 1, text: 'Foo'}, {id: 2, text: 'Bar'}],
@@ -168,40 +184,40 @@ describe Acfs::Stub do
168
184
  let(:headers) do
169
185
  {
170
186
  'X-Total-Pages' => '2',
171
- 'X-Total-Count' => '10'
187
+ 'X-Total-Count' => '10',
172
188
  }
173
189
  end
174
- subject { Acfs.run; comments }
175
190
 
176
- its(:total_pages) { should eq 2 }
177
- its(:total_count) { should eq 10 }
191
+ its(:total_pages) { is_expected.to eq 2 }
192
+ its(:total_count) { is_expected.to eq 10 }
178
193
  end
179
194
  end
180
195
 
181
196
  context 'with update action' do
182
197
  before do
183
198
  Acfs::Stub.resource MyUser, :read, with: {id: 1}, return: {id: 1, name: 'John Smith', age: 32}
184
- Acfs::Stub.resource MyUser, :update, with: {id: 1, name: 'John Smith', age: 22}, return: {id: 1, name: 'John Smith', age: 23}
199
+ Acfs::Stub.resource MyUser, :update, with: {id: 1, name: 'John Smith', age: 22},
200
+ return: {id: 1, name: 'John Smith', age: 23}
185
201
  Acfs::Stub.resource MyUser, :update, with: {id: 1, name: 'John Smith', age: 0}, raise: 422
186
202
  end
187
203
 
188
204
  let!(:update_stub) do
189
205
  Acfs::Stub.resource MyUser, :update,
190
206
  with: {id: 1, name: 'Jane Smith'},
191
- return: ->(op) { Hash[op.data.map {|k, v| [k, v.to_s.upcase] }] }
207
+ return: ->(op) { op.data.map {|k, v| [k, v.to_s.upcase] }.to_h }
192
208
  end
193
209
 
194
- it 'should allow stub resource update' do
210
+ it 'allows stub resource update' do
195
211
  user = MyUser.find 1
196
212
  Acfs.run
197
213
 
198
214
  user.age = 22
199
215
  user.save!
200
216
 
201
- expect(user.age).to be == 23
217
+ expect(user.age).to eq 23
202
218
  end
203
219
 
204
- it 'should allow to raise error' do
220
+ it 'allows to raise error' do
205
221
  user = MyUser.find 1
206
222
  Acfs.run
207
223
 
@@ -213,7 +229,7 @@ describe Acfs::Stub do
213
229
  end.to raise_error(::Acfs::InvalidResource)
214
230
  end
215
231
 
216
- it 'should match partial :with' do
232
+ it 'matches partial :with' do
217
233
  user = MyUser.find 1
218
234
  Acfs.run
219
235
 
@@ -224,7 +240,7 @@ describe Acfs::Stub do
224
240
  expect(update_stub).to be_called
225
241
  end
226
242
 
227
- it 'should process response body' do
243
+ it 'processes response body' do
228
244
  user = MyUser.find 1
229
245
  Acfs.run
230
246
 
@@ -235,18 +251,6 @@ describe Acfs::Stub do
235
251
  expect(user.name).to eq 'JANE SMITH'
236
252
  end
237
253
  end
238
-
239
- context 'with create action' do
240
- before do
241
- Acfs::Stub.resource MyUser, :create, with: {name: 'John Smith', age: 0}, raise: 422
242
- end
243
-
244
- it 'should allow to raise error' do
245
- expect do
246
- MyUser.create! name: 'John Smith', age: 0
247
- end.to raise_error(::Acfs::InvalidResource)
248
- end
249
- end
250
254
  end
251
255
 
252
256
  describe '.allow_requests=' do
@@ -256,9 +260,9 @@ describe Acfs::Stub do
256
260
  stub_request(:get, 'http://users.example.org/users/2').to_return response(id: 2, name: 'John', age: 26)
257
261
  end
258
262
 
259
- it 'should allow real requests' do
263
+ it 'allows real requests' do
260
264
  @user = MyUser.find 2
261
- expect { Acfs.run }.to_not raise_error
265
+ expect { Acfs.run }.not_to raise_error
262
266
  end
263
267
  end
264
268
 
@@ -267,7 +271,7 @@ describe Acfs::Stub do
267
271
  Acfs::Stub.allow_requests = false
268
272
  end
269
273
 
270
- it 'should not allow real requests' do
274
+ it 'does not allow real requests' do
271
275
  @user = MyUser.find 2
272
276
  expect { Acfs.run }.to raise_error(Acfs::RealRequestsNotAllowedError)
273
277
  end
@@ -279,7 +283,7 @@ describe Acfs::Stub do
279
283
 
280
284
  context 'with a match in params' do
281
285
  let(:op) do
282
- double('operation').tap do |op|
286
+ instance_double('Acfs::Operation').tap do |op|
283
287
  allow(op).to receive(:full_params).and_return(id: 1337, blub: 'abc')
284
288
  allow(op).to receive(:data).and_return({})
285
289
  end
@@ -292,7 +296,7 @@ describe Acfs::Stub do
292
296
 
293
297
  context 'with a match in data' do
294
298
  let(:op) do
295
- double('operation').tap do |op|
299
+ instance_double('Acfs::Operation').tap do |op|
296
300
  allow(op).to receive(:full_params).and_return({})
297
301
  allow(op).to receive(:data).and_return(id: 1337, blub: 'abc')
298
302
  end
@@ -305,7 +309,7 @@ describe Acfs::Stub do
305
309
 
306
310
  context 'with no match in params nor data' do
307
311
  let(:op) do
308
- double('operation').tap do |op|
312
+ instance_double('Acfs::Operation').tap do |op|
309
313
  allow(op).to receive(:full_params).and_return(id: 1337)
310
314
  allow(op).to receive(:data).and_return({})
311
315
  end
@@ -318,7 +322,7 @@ describe Acfs::Stub do
318
322
 
319
323
  context 'with a wrong match' do
320
324
  let(:op) do
321
- double('operation').tap do |op|
325
+ instance_double('Acfs::Operation').tap do |op|
322
326
  allow(op).to receive(:full_params).and_return(id: 1337, blub: 'abc')
323
327
  allow(op).to receive(:data).and_return({})
324
328
  end
@@ -331,7 +335,7 @@ describe Acfs::Stub do
331
335
 
332
336
  context 'with a missing match' do
333
337
  let(:op) do
334
- double('operation').tap do |op|
338
+ instance_double('Acfs::Operation').tap do |op|
335
339
  allow(op).to receive(:full_params).and_return(id: 1337, blub: 'abc')
336
340
  allow(op).to receive(:data).and_return({})
337
341
  end
data/spec/acfs_spec.rb CHANGED
@@ -4,57 +4,68 @@ require 'spec_helper'
4
4
 
5
5
  describe 'Acfs' do
6
6
  before do
7
- stub_request(:get, 'http://users.example.org/users').to_return response([{id: 1, name: 'Anon', age: 12}, {id: 2, name: 'John', age: 26}])
8
- stub_request(:get, 'http://users.example.org/users/2').to_return response(id: 2, name: 'John', age: 26)
9
- stub_request(:get, 'http://users.example.org/users/3').to_return response(id: 3, name: 'Miraculix', age: 122)
10
- stub_request(:get, 'http://users.example.org/users/100').to_return response(id: 100, name: 'Jimmy', age: 45)
11
- stub_request(:get, 'http://users.example.org/users/2/friends').to_return response([{id: 1, name: 'Anon', age: 12}])
12
- stub_request(:get, 'http://comments.example.org/comments?user=2').to_return response([{id: 1, text: 'Comment #1'}, {id: 2, text: 'Comment #2'}])
7
+ stub_request(:get, 'http://users.example.org/users')
8
+ .to_return response([{id: 1, name: 'Anon', age: 12}, {id: 2, name: 'John', age: 26}])
9
+
10
+ stub_request(:get, 'http://users.example.org/users/2')
11
+ .to_return response(id: 2, name: 'John', age: 26)
12
+
13
+ stub_request(:get, 'http://users.example.org/users/3')
14
+ .to_return response(id: 3, name: 'Miraculix', age: 122)
15
+
16
+ stub_request(:get, 'http://users.example.org/users/100')
17
+ .to_return response(id: 100, name: 'Jimmy', age: 45)
18
+
19
+ stub_request(:get, 'http://users.example.org/users/2/friends')
20
+ .to_return response([{id: 1, name: 'Anon', age: 12}])
21
+
22
+ stub_request(:get, 'http://comments.example.org/comments?user=2')
23
+ .to_return response([{id: 1, text: 'Comment #1'}, {id: 2, text: 'Comment #2'}])
13
24
  end
14
25
 
15
- it 'should update single resource synchronously' do
26
+ it 'updates single resource synchronously' do
16
27
  stub = stub_request(:put, 'http://users.example.org/users/2')
17
- .to_return {|request| {body: request.body, headers: {'Content-Type' => request.headers['Content-Type']}} }
28
+ .to_return {|request| {body: request.body, headers: {'Content-Type' => request.headers['Content-Type']}} }
18
29
 
19
- @user = MyUser.find 2
30
+ user = MyUser.find 2
20
31
  Acfs.run
21
32
 
22
- expect(@user).to_not be_changed
23
- expect(@user).to be_persisted
33
+ expect(user).not_to be_changed
34
+ expect(user).to be_persisted
24
35
 
25
- @user.name = 'Johnny'
36
+ user.name = 'Johnny'
26
37
 
27
- expect(@user).to be_changed
28
- expect(@user).to be_persisted
38
+ expect(user).to be_changed
39
+ expect(user).to be_persisted
29
40
 
30
- @user.save
41
+ user.save
31
42
 
32
43
  expect(stub).to have_been_requested
33
- expect(@user).to_not be_changed
34
- expect(@user).to be_persisted
44
+ expect(user).not_to be_changed
45
+ expect(user).to be_persisted
35
46
  end
36
47
 
37
- it 'should create a single resource synchronously' do
48
+ it 'creates a single resource synchronously' do
38
49
  stub = stub_request(:post, 'http://users.example.org/sessions').to_return response(id: 'sessionhash', user: 1)
39
50
 
40
51
  session = Session.create ident: 'Anon'
41
52
 
42
53
  expect(stub).to have_been_requested
43
- expect(session.id).to be == 'sessionhash'
44
- expect(session.user).to be == 1
54
+ expect(session.id).to eq 'sessionhash'
55
+ expect(session.user).to eq 1
45
56
  end
46
57
 
47
- it 'should load single resource' do
48
- @user = MyUser.find(2)
58
+ it 'loads single resource' do
59
+ user = MyUser.find(2)
49
60
 
50
- expect(@user).to_not be_loaded
61
+ expect(user).not_to be_loaded
51
62
 
52
63
  Acfs.run
53
64
 
54
- expect(@user).to be_loaded
55
- expect(@user.id).to be == 2
56
- expect(@user.name).to be == 'John'
57
- expect(@user.age).to be == 26
65
+ expect(user).to be_loaded
66
+ expect(user.id).to eq 2
67
+ expect(user.name).to eq 'John'
68
+ expect(user.age).to eq 26
58
69
  end
59
70
 
60
71
  describe 'singleton' do
@@ -62,144 +73,151 @@ describe 'Acfs' do
62
73
  stub_request(:get, 'http://users.example.org/singles?user_id=5').to_return response(score: 250, user_id: 5)
63
74
  end
64
75
 
65
- it 'should create a singleton resource' do
76
+ it 'creates a singleton resource' do
66
77
  stub = stub_request(:post, 'http://users.example.org/singles').to_return response(score: 250, user_id: 5)
67
78
 
68
- @single = Single.new user_id: 5, score: 250
69
- expect(@single.new?).to eq true
79
+ single = Single.new user_id: 5, score: 250
80
+ expect(single.new?).to eq true
70
81
 
71
- @single.save
82
+ single.save
72
83
  expect(stub).to have_been_requested
73
84
 
74
- expect(@single.new?).to eq false
75
- expect(@single.user_id).to eq 5
76
- expect(@single.score).to eq 250
85
+ expect(single.new?).to eq false
86
+ expect(single.user_id).to eq 5
87
+ expect(single.score).to eq 250
77
88
  end
78
89
 
79
- it 'should load singleton resource' do
80
- @single = Single.find user_id: 5
90
+ it 'loads singleton resource' do
91
+ single = Single.find user_id: 5
81
92
  Acfs.run
82
93
 
83
- expect(@single.score).to eq 250
94
+ expect(single.score).to eq 250
84
95
  end
85
96
 
86
- it 'should update singleton resource' do
97
+ it 'updates singleton resource' do
87
98
  stub = stub_request(:put, 'http://users.example.org/singles').to_return do |request|
88
99
  {
89
100
  body: request.body,
90
- headers: {'Content-Type' => request.headers['Content-Type']}
101
+ headers: {'Content-Type' => request.headers['Content-Type']},
91
102
  }
92
103
  end
93
104
 
94
- @single = Single.find user_id: 5
105
+ single = Single.find user_id: 5
95
106
  Acfs.run
96
107
 
97
- expect(@single.score).to eq 250
108
+ expect(single.score).to eq 250
98
109
 
99
- @single.score = 300
100
- @single.save
110
+ single.score = 300
111
+ single.save
101
112
 
102
113
  expect(stub).to have_been_requested
103
114
 
104
- expect(@single.score).to eq 300
115
+ expect(single.score).to eq 300
105
116
  end
106
117
 
107
- it 'should delete singleton resource' do
118
+ it 'deletes singleton resource' do
108
119
  stub = stub_request(:delete, 'http://users.example.org/singles').to_return do |request|
109
120
  {
110
121
  body: request.body,
111
- headers: {'Content-Type' => request.headers['Content-Type']}
122
+ headers: {'Content-Type' => request.headers['Content-Type']},
112
123
  }
113
124
  end
114
125
 
115
- @single = Single.find user_id: 5
126
+ single = Single.find user_id: 5
116
127
  Acfs.run
117
128
 
118
- expect(@single.new?).to eq false
129
+ expect(single.new?).to eq false
119
130
 
120
- @single.delete
131
+ single.delete
121
132
 
122
133
  expect(stub).to have_been_requested
123
134
  end
124
135
 
125
- it 'should raise error when calling `all\'' do
136
+ it 'raises error when calling .all' do
126
137
  expect { Single.all }.to raise_error ::Acfs::UnsupportedOperation
127
138
  end
128
139
  end
129
140
 
130
- it 'should load multiple single resources' do
131
- @users = MyUser.find([2, 3, 100]) do |users|
141
+ it 'loads multiple single resources' do
142
+ john = nil
143
+ mirx = nil
144
+ jimy = nil
145
+
146
+ users = MyUser.find([2, 3, 100]) do |users|
132
147
  # This block should be called only after *all* resources are loaded.
133
- @john = users[0]
134
- @mirx = users[1]
135
- @jimy = users[2]
148
+ john = users[0]
149
+ mirx = users[1]
150
+ jimy = users[2]
136
151
  end
137
152
 
138
- expect(@users).to_not be_loaded
153
+ expect(users).not_to be_loaded
139
154
 
140
155
  Acfs.run
141
156
 
142
- expect(@users).to be_loaded
143
- expect(@users).to have(3).items
157
+ expect(users).to be_loaded
158
+ expect(users).to have(3).items
144
159
 
145
- expect(@users[0].id).to be == 2
146
- expect(@users[0].name).to be == 'John'
147
- expect(@users[0].age).to be == 26
148
- expect(@users[0]).to be == @john
160
+ expect(users[0].id).to eq 2
161
+ expect(users[0].name).to eq 'John'
162
+ expect(users[0].age).to eq 26
163
+ expect(users[0]).to eq john
149
164
 
150
- expect(@users[1].id).to be == 3
151
- expect(@users[1].name).to be == 'Miraculix'
152
- expect(@users[1].age).to be == 122
153
- expect(@users[1]).to be == @mirx
165
+ expect(users[1].id).to eq 3
166
+ expect(users[1].name).to eq 'Miraculix'
167
+ expect(users[1].age).to eq 122
168
+ expect(users[1]).to eq mirx
154
169
 
155
- expect(@users[2].id).to be == 100
156
- expect(@users[2].name).to be == 'Jimmy'
157
- expect(@users[2].age).to be == 45
158
- expect(@users[2]).to be == @jimy
170
+ expect(users[2].id).to eq 100
171
+ expect(users[2].name).to eq 'Jimmy'
172
+ expect(users[2].age).to eq 45
173
+ expect(users[2]).to eq jimy
159
174
  end
160
175
 
161
- it 'should load multiple resources' do
162
- @users = MyUser.all
176
+ it 'loads multiple resources' do
177
+ users = MyUser.all
163
178
 
164
- expect(@users).to_not be_loaded
179
+ expect(users).not_to be_loaded
165
180
 
166
181
  Acfs.run
167
182
 
168
- expect(@users).to be_loaded
169
- expect(@users).to have(2).items
170
- expect(@users[0].name).to be == 'Anon'
171
- expect(@users[0].age).to be == 12
172
- expect(@users[1].name).to be == 'John'
173
- expect(@users[1].age).to be == 26
183
+ expect(users).to be_loaded
184
+ expect(users).to have(2).items
185
+ expect(users[0].name).to eq 'Anon'
186
+ expect(users[0].age).to eq 12
187
+ expect(users[1].name).to eq 'John'
188
+ expect(users[1].age).to eq 26
174
189
  end
175
190
 
176
- it 'should load associated resources' do
191
+ it 'loads associated resources' do
177
192
  pending 'TODO: Implement high level feature'
193
+ friends = nil
178
194
 
179
- @user = MyUser.find(2) do |user|
180
- @friends = user.friends.all
195
+ user = MyUser.find(2) do |user|
196
+ friends = user.friends.all
181
197
  end
182
198
 
183
199
  Acfs.run
184
200
 
185
- expect(@user.name).to be == 'John'
186
- expect(@user.age).to be == 26
201
+ expect(user.name).to eq 'John'
202
+ expect(user.age).to eq 26
187
203
 
188
- expect(@friends).to have(1).items
204
+ expect(friends).to have(1).items
189
205
  end
190
206
 
191
- it 'should load associated resources from different service' do
192
- @user = MyUser.find 2 do |user|
193
- expect(user.id).to be == 2
194
- @comments = Comment.where user: user.id
207
+ it 'loads associated resources from different service' do
208
+ comments = nil
209
+
210
+ user = MyUser.find 2 do |user|
211
+ expect(user.id).to eq 2
212
+ comments = Comment.where({user: user.id})
195
213
  end
196
214
 
197
215
  Acfs.run
198
216
 
199
- expect(@user.id).to be == 2
200
- expect(@user.name).to be == 'John'
201
- expect(@user.age).to be == 26
217
+ expect(user.id).to eq 2
218
+ expect(user.name).to eq 'John'
219
+ expect(user.age).to eq 26
202
220
 
203
- expect(@comments).to have(2).items
221
+ expect(comments).to have(2).items
204
222
  end
205
223
  end
data/spec/spec_helper.rb CHANGED
@@ -17,7 +17,6 @@ require 'bundler'
17
17
  Bundler.require(:default, :test)
18
18
 
19
19
  require 'acfs'
20
- require 'webmock/rspec'
21
20
 
22
21
  Dir[File.expand_path('spec/support/**/*.rb')].sort.each {|f| require f }
23
22
 
@@ -36,7 +35,7 @@ RSpec.configure do |config|
36
35
  # --seed 1234
37
36
  config.order = 'random'
38
37
 
39
- config.before :each do
38
+ config.before do
40
39
  Acfs.runner.clear
41
40
  Acfs::Stub.clear
42
41
  end
@@ -4,9 +4,9 @@ require 'json'
4
4
 
5
5
  def response(data = nil, opts = {})
6
6
  if data
7
- opts.merge! body: JSON.dump(data)
7
+ opts[:body] = JSON.dump(data)
8
8
  opts[:headers] ||= {}
9
- opts[:headers].merge! 'Content-Type' => 'application/json'
9
+ opts[:headers]['Content-Type'] = 'application/json'
10
10
  end
11
11
  opts
12
12
  end
@@ -45,7 +45,7 @@ class Session < Acfs::Resource
45
45
  service UserService, path: {
46
46
  list: 'users/:user_id/sessions',
47
47
  delete: 'users/:user_id/sessions/del/:id',
48
- update: nil
48
+ update: nil,
49
49
  }
50
50
 
51
51
  attribute :id, :string