arstotzka 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,7 +23,7 @@ describe Arstotzka::MethodBuilder do
23
23
  let(:attr_names) { [attr_name] }
24
24
  let(:json) { {} }
25
25
  let(:instance) { klass.new(json) }
26
- let(:full_options) { Arstotzka::Options::DEFAULT_OPTIONS.merge(options) }
26
+ let(:full_options) { Arstotzka::Config::DEFAULT_CONFIGS.merge(options) }
27
27
 
28
28
  describe '#build' do
29
29
  context 'when it is called' do
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Arstotzka::Options do
6
- subject(:options) { described_class.new(options_hash) }
6
+ subject(:options) { Arstotzka.config.options(options_hash) }
7
7
 
8
8
  context 'when initializing without options' do
9
9
  let(:options_hash) { {} }
@@ -200,4 +200,167 @@ describe Arstotzka do
200
200
  expect(value).to eq(json['user']['name'])
201
201
  end
202
202
  end
203
+
204
+ context 'when changing configuration of case after class declaration' do
205
+ let(:json) { { the_value: 'snake', theValue: 'lower_camel', TheValue: 'upper_camel' } }
206
+
207
+ let(:dummy_class) do
208
+ Class.new(Arstotzka::Dummy) do
209
+ expose :the_value
210
+ end
211
+ end
212
+
213
+ after { described_class.reset_config }
214
+
215
+ context 'when changing case to snake' do
216
+ it 'changes the way the value is fetched' do
217
+ expect { described_class.configure { |c| c.case :snake } }
218
+ .to change(dummy, :the_value)
219
+ .from('lower_camel').to('snake')
220
+ end
221
+ end
222
+
223
+ context 'when changing case to upper_camel' do
224
+ it 'changes the way the value is fetched' do
225
+ expect { described_class.configure { |c| c.case :upper_camel } }
226
+ .to change(dummy, :the_value)
227
+ .from('lower_camel').to('upper_camel')
228
+ end
229
+ end
230
+
231
+ context 'when expose was set to cache' do
232
+ let(:dummy_class) do
233
+ Class.new(Arstotzka::Dummy) do
234
+ expose :the_value, cached: true
235
+ end
236
+ end
237
+
238
+ it 'does not change the way the value is fetched' do
239
+ expect { described_class.configure { |c| c.case :snake } }
240
+ .not_to change(dummy, :the_value)
241
+ end
242
+ end
243
+
244
+ context 'when arstotka was set to cache' do
245
+ before { described_class.configure { cached true } }
246
+
247
+ it 'does not change the way the value is fetched' do
248
+ expect { described_class.configure { |c| c.case :snake } }
249
+ .not_to change(dummy, :the_value)
250
+ end
251
+ end
252
+
253
+ context 'when expose defined the case' do
254
+ let(:dummy_class) do
255
+ Class.new(Arstotzka::Dummy) do
256
+ expose :the_value, case: :upper_camel
257
+ end
258
+ end
259
+
260
+ it 'does not change the way the value is fetched' do
261
+ expect { described_class.configure { |c| c.case :snake } }
262
+ .not_to change(dummy, :the_value)
263
+ end
264
+ end
265
+ end
266
+
267
+ context 'when changing configuration of cached after class declaration' do
268
+ let(:json) { { the_value: 'old value' } }
269
+
270
+ let(:dummy_class) do
271
+ Class.new(Arstotzka::Dummy) do
272
+ expose :the_value, case: :snake
273
+ end
274
+ end
275
+
276
+ after { described_class.reset_config }
277
+
278
+ context 'when cached is defined as true after in the config' do
279
+ context 'when first method call is after value change' do
280
+ let(:block) do
281
+ proc do
282
+ described_class.configure { cached true }
283
+ json[:the_value] = :symbol
284
+ end
285
+ end
286
+
287
+ it 'caches after cache change' do
288
+ expect(&block).to change(dummy, :the_value)
289
+ .from('old value').to(:symbol)
290
+ end
291
+ end
292
+
293
+ context 'when first method call is before value change' do
294
+ let(:block) do
295
+ proc do
296
+ described_class.configure { cached true }
297
+ dummy.the_value
298
+ json[:the_value] = :symbol
299
+ end
300
+ end
301
+
302
+ it 'caches the original value' do
303
+ expect(&block).not_to change(dummy, :the_value)
304
+ end
305
+ end
306
+ end
307
+
308
+ context 'when cached is defined as false after in the config' do
309
+ before { described_class.configure { cached true } }
310
+
311
+ let(:block) do
312
+ proc do
313
+ described_class.configure { cached false }
314
+ json[:the_value] = :symbol
315
+ end
316
+ end
317
+
318
+ it 'changes value' do
319
+ expect(&block).to change(dummy, :the_value)
320
+ .from('old value').to(:symbol)
321
+ end
322
+ end
323
+
324
+ context 'when cached was defined in expose' do
325
+ context 'when cached was set as true' do
326
+ let(:dummy_class) do
327
+ Class.new(Arstotzka::Dummy) do
328
+ expose :the_value, case: :snake, cached: true
329
+ end
330
+ end
331
+
332
+ let(:block) do
333
+ proc do
334
+ described_class.configure { cached false }
335
+ json[:the_value] = :symbol
336
+ end
337
+ end
338
+
339
+ it 'does not change cached state' do
340
+ expect(&block).not_to change(dummy, :the_value)
341
+ end
342
+ end
343
+
344
+ context 'when cached was set as false' do
345
+ let(:dummy_class) do
346
+ Class.new(Arstotzka::Dummy) do
347
+ expose :the_value, case: :snake, cached: false
348
+ end
349
+ end
350
+
351
+ let(:block) do
352
+ proc do
353
+ described_class.configure { cached true }
354
+ dummy.the_value
355
+ json[:the_value] = :symbol
356
+ end
357
+ end
358
+
359
+ it 'does not change cached state' do
360
+ expect(&block).to change(dummy, :the_value)
361
+ .from('old value').to(:symbol)
362
+ end
363
+ end
364
+ end
365
+ end
203
366
  end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'simplecov'
4
4
  SimpleCov.start do
5
- add_filter 'spec/support/models/'
5
+ add_filter 'spec/'
6
6
  end
7
7
 
8
8
  require 'pry-nav'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Restaurant
4
+ include Arstotzka
5
+
6
+ expose :dishes, path: 'restaurant.complete_meals'
7
+
8
+ def initialize(hash)
9
+ @hash = hash
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arstotzka
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darthjee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-07 00:00:00.000000000 Z
11
+ date: 2019-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2.1
33
+ version: 1.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.2.1
40
+ version: 1.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -220,9 +220,11 @@ files:
220
220
  - lib/arstotzka.rb
221
221
  - lib/arstotzka/base.rb
222
222
  - lib/arstotzka/class_methods.rb
223
+ - lib/arstotzka/config.rb
223
224
  - lib/arstotzka/crawler.rb
224
225
  - lib/arstotzka/exception.rb
225
226
  - lib/arstotzka/fetcher.rb
227
+ - lib/arstotzka/fetcher/cache.rb
226
228
  - lib/arstotzka/fetcher_builder.rb
227
229
  - lib/arstotzka/hash_reader.rb
228
230
  - lib/arstotzka/key_reader.rb
@@ -239,10 +241,13 @@ files:
239
241
  - spec/fixtures/arstotzka.json
240
242
  - spec/fixtures/complete_person.json
241
243
  - spec/fixtures/person.json
244
+ - spec/integration/readme/arstotzka/config_spec.rb
242
245
  - spec/integration/readme/arstotzka_spec.rb
243
246
  - spec/integration/readme/my_parser_spec.rb
244
247
  - spec/integration/yard/arstotzka/class_methods_spec.rb
248
+ - spec/integration/yard/arstotzka/config_spec.rb
245
249
  - spec/integration/yard/arstotzka/crawler_spec.rb
250
+ - spec/integration/yard/arstotzka/fetcher/cache_spec.rb
246
251
  - spec/integration/yard/arstotzka/fetcher_builder_spec.rb
247
252
  - spec/integration/yard/arstotzka/fetcher_spec.rb
248
253
  - spec/integration/yard/arstotzka/hash_reader_spec.rb
@@ -253,7 +258,9 @@ files:
253
258
  - spec/integration/yard/arstotzka/type_cast_spec.rb
254
259
  - spec/integration/yard/arstotzka/wrapper_spec.rb
255
260
  - spec/integration/yard/arstotzka_spec.rb
261
+ - spec/lib/arstotzka/config_spec.rb
256
262
  - spec/lib/arstotzka/crawler_spec.rb
263
+ - spec/lib/arstotzka/fetcher/cache_spec.rb
257
264
  - spec/lib/arstotzka/fetcher_builder_spec.rb
258
265
  - spec/lib/arstotzka/fetcher_spec.rb
259
266
  - spec/lib/arstotzka/hash_reader_spec.rb
@@ -290,6 +297,7 @@ files:
290
297
  - spec/support/models/my_parser.rb
291
298
  - spec/support/models/person.rb
292
299
  - spec/support/models/request.rb
300
+ - spec/support/models/restaurant.rb
293
301
  - spec/support/models/shopping_mall.rb
294
302
  - spec/support/models/star.rb
295
303
  - spec/support/models/star_gazer.rb
@@ -326,10 +334,13 @@ test_files:
326
334
  - spec/fixtures/arstotzka.json
327
335
  - spec/fixtures/complete_person.json
328
336
  - spec/fixtures/person.json
337
+ - spec/integration/readme/arstotzka/config_spec.rb
329
338
  - spec/integration/readme/arstotzka_spec.rb
330
339
  - spec/integration/readme/my_parser_spec.rb
331
340
  - spec/integration/yard/arstotzka/class_methods_spec.rb
341
+ - spec/integration/yard/arstotzka/config_spec.rb
332
342
  - spec/integration/yard/arstotzka/crawler_spec.rb
343
+ - spec/integration/yard/arstotzka/fetcher/cache_spec.rb
333
344
  - spec/integration/yard/arstotzka/fetcher_builder_spec.rb
334
345
  - spec/integration/yard/arstotzka/fetcher_spec.rb
335
346
  - spec/integration/yard/arstotzka/hash_reader_spec.rb
@@ -340,7 +351,9 @@ test_files:
340
351
  - spec/integration/yard/arstotzka/type_cast_spec.rb
341
352
  - spec/integration/yard/arstotzka/wrapper_spec.rb
342
353
  - spec/integration/yard/arstotzka_spec.rb
354
+ - spec/lib/arstotzka/config_spec.rb
343
355
  - spec/lib/arstotzka/crawler_spec.rb
356
+ - spec/lib/arstotzka/fetcher/cache_spec.rb
344
357
  - spec/lib/arstotzka/fetcher_builder_spec.rb
345
358
  - spec/lib/arstotzka/fetcher_spec.rb
346
359
  - spec/lib/arstotzka/hash_reader_spec.rb
@@ -377,6 +390,7 @@ test_files:
377
390
  - spec/support/models/my_parser.rb
378
391
  - spec/support/models/person.rb
379
392
  - spec/support/models/request.rb
393
+ - spec/support/models/restaurant.rb
380
394
  - spec/support/models/shopping_mall.rb
381
395
  - spec/support/models/star.rb
382
396
  - spec/support/models/star_gazer.rb