lhs 15.2.3.pre.favorites.1 → 15.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f38ffdbc961e4017dc1d0d69061fd095dfb14bcd
4
- data.tar.gz: 260c6c9c52daea2d9d87465d6b64e6454b0fff38
3
+ metadata.gz: ab8ba71d671d0e6b04f578b81bd6988a3caa5b28
4
+ data.tar.gz: 17222267f2563042bb2975fdc2c778662d1594db
5
5
  SHA512:
6
- metadata.gz: 4adb473a75f4bdb1fb98d79a64ce3f520d18f4ed8d1e491e11d364d4d2e144ac7b85928d35b17e7b40bcf293f388325bd24fc0046dcbd985ef48c9f45d00a6f4
7
- data.tar.gz: 9b62a3f7cea553e4b0602f4148db60ab6feb4a704ea90cf4d64ffc732bced80f21d95d106207dfbd41f96332bea6339edcaba1206c3a4dabfa9152bb1784c401
6
+ metadata.gz: 79414764f2beed745b3dcaa21cd9d9f099c432715080a54cfa0463d9c2d91ea4ccc55ac098353df21234b60a2661463152c984669b0590154c62aab8ac010757
7
+ data.tar.gz: 13cc0ab0000e9fde6e731835b8343a434dd4e2d64cd70f3a4a3c9ef6cdf5d707853e0dea6956b108297dfd804af5d7d98f99f317691fe5dea547c972dccbd9d0
@@ -267,18 +267,15 @@ class LHS::Record
267
267
 
268
268
  def load_and_merge_set_of_paginated_collections!(data, options)
269
269
  options_for_this_batch = []
270
- data_record = data._record
271
- data = data.compact
272
- options.compact.each_with_index do |_, index|
270
+ options.each_with_index do |element, index|
271
+ next if element.nil?
273
272
  record = data[index]._record
274
273
  pagination = record.pagination(data[index])
275
274
  next if pagination.pages_left.zero?
276
275
  options_for_this_batch.push(options_for_next_batch(record, pagination, options[index], data[index]))
277
276
  end
278
- if data_record.present?
279
- data_record.request(options_for_this_batch.flatten).each do |batch_data|
280
- merge_batch_data_with_parent!(batch_data, batch_data._request.options[:parent_data])
281
- end
277
+ data._record.request(options_for_this_batch.flatten).each do |batch_data|
278
+ merge_batch_data_with_parent!(batch_data, batch_data._request.options[:parent_data])
282
279
  end
283
280
  end
284
281
 
data/lib/lhs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '15.2.3-favorites.1'
2
+ VERSION = '15.2.3'
3
3
  end
@@ -73,40 +73,4 @@ describe LHS::Record::Request do
73
73
  params: { limit: 100 })
74
74
  end
75
75
  end
76
-
77
- describe 'load_and_merge_set_of_paginated_collections!' do
78
- let(:options) do
79
- [
80
- {
81
- url: 'http://localhost:3000/test/resource?abc=def&limit=1&offset=3&test=1',
82
- all: true,
83
- auth: { bearer: 'xxx' },
84
- params: { limit: 100 }
85
- },
86
- nil,
87
- {
88
- url: 'http://localhost:3000/test/resource?abc=def&limit=1&offset=3&test=3',
89
- all: true,
90
- auth: { bearer: 'xxx' },
91
- params: { limit: 100 }
92
- },
93
- ]
94
- end
95
-
96
- let(:data_array) do
97
- [
98
- LHS::Record.new,
99
- nil,
100
- LHS::Record.new,
101
- ]
102
- end
103
-
104
- let(:data) do
105
- LHS::Record.new(data_array)
106
- end
107
-
108
- it 'does not raise an error when data has nil objects' do
109
- expect(subject.send(:load_and_merge_set_of_paginated_collections!, data, options)).to_not be_nil
110
- end
111
- end
112
76
  end
@@ -384,19 +384,8 @@ describe LHS::Record do
384
384
 
385
385
  context 'nested includes_all' do
386
386
  context 'with optional children' do
387
- before do
388
- class Favorite < LHS::Record
389
- endpoint 'http://datastore/favorites'
390
- end
391
-
392
- class Place < LHS::Record
393
- endpoint 'http://datastore/places/{id}'
394
- end
395
-
396
- class Contract < LHS::Record
397
- endpoint 'http://datastore/places/{place_id}/contracts'
398
- end
399
387
 
388
+ let(:favorites_request_stub) do
400
389
  stub_request(:get, %r{http://datastore/favorites})
401
390
  .to_return(
402
391
  body: {
@@ -410,13 +399,20 @@ describe LHS::Record do
410
399
  place: {
411
400
  href: "http://datastore/places/2"
412
401
  }
402
+ }, {
403
+ href: "http://datastore/favorite/3",
404
+ place: {
405
+ href: "http://datastore/places/3"
406
+ }
413
407
  }],
414
- total: 2,
408
+ total: 3,
415
409
  offset: 0,
416
410
  limit: 100
417
411
  }.to_json
418
412
  )
413
+ end
419
414
 
415
+ let(:place1_request_stub) do
420
416
  stub_request(:get, %r{http://datastore/places/1})
421
417
  .to_return(
422
418
  body: {
@@ -427,7 +423,32 @@ describe LHS::Record do
427
423
  }
428
424
  }.to_json
429
425
  )
426
+ end
427
+
428
+ let(:place2_request_stub) do
429
+ stub_request(:get, %r{http://datastore/places/2})
430
+ .to_return(
431
+ body: {
432
+ href: "http://datastore/places/2",
433
+ name: 'Place 2'
434
+ }.to_json
435
+ )
436
+ end
430
437
 
438
+ let(:place3_request_stub) do
439
+ stub_request(:get, %r{http://datastore/places/3})
440
+ .to_return(
441
+ body: {
442
+ href: "http://datastore/places/3",
443
+ name: 'Place 3',
444
+ contracts: {
445
+ href: "http://datastore/places/3/contracts"
446
+ }
447
+ }.to_json
448
+ )
449
+ end
450
+
451
+ let(:contracts_request_for_place1_stub) do
431
452
  stub_request(:get, %r{http://datastore/places/1/contracts})
432
453
  .to_return(
433
454
  body: {
@@ -440,16 +461,44 @@ describe LHS::Record do
440
461
  limit: 10
441
462
  }.to_json
442
463
  )
464
+ end
443
465
 
444
- stub_request(:get, %r{http://datastore/places/2})
466
+ let(:contracts_request_for_place3_stub) do
467
+ stub_request(:get, %r{http://datastore/places/3/contracts})
445
468
  .to_return(
446
469
  body: {
447
- href: "http://datastore/places/2",
448
- name: 'Place 2'
470
+ items: [{
471
+ href: "http://datastore/places/3/contracts/1",
472
+ name: 'Contract 3'
473
+ }],
474
+ total: 1,
475
+ offset: 0,
476
+ limit: 10
449
477
  }.to_json
450
478
  )
451
479
  end
452
480
 
481
+ before do
482
+ class Favorite < LHS::Record
483
+ endpoint 'http://datastore/favorites'
484
+ end
485
+
486
+ class Place < LHS::Record
487
+ endpoint 'http://datastore/places/{id}'
488
+ end
489
+
490
+ class Contract < LHS::Record
491
+ endpoint 'http://datastore/places/{place_id}/contracts'
492
+ end
493
+
494
+ favorites_request_stub
495
+ place1_request_stub
496
+ place2_request_stub
497
+ place3_request_stub
498
+ contracts_request_for_place1_stub
499
+ contracts_request_for_place3_stub
500
+ end
501
+
453
502
  it 'includes nested objects when they exist' do
454
503
  favorites = Favorite.includes(:place).includes_all(place: :contracts).all
455
504
 
@@ -460,8 +509,15 @@ describe LHS::Record do
460
509
  it 'does not include nested objects when they are not there' do
461
510
  favorites = Favorite.includes(:place).includes_all(place: :contracts).all
462
511
 
463
- expect(favorites.last.place.name).to eq('Place 2')
464
- expect(favorites.last.place.contracts).to be(nil)
512
+ expect(favorites[1].place.name).to eq('Place 2')
513
+ expect(favorites[1].place.contracts).to be(nil)
514
+ end
515
+
516
+ it 'does include and merges objects after nil objects in collections' do
517
+ favorites = Favorite.includes(:place).includes_all(place: :contracts).all
518
+
519
+ expect(favorites.last.place.name).to eq('Place 3')
520
+ expect(favorites.last.place.contracts.first.name).to eq('Contract 3')
465
521
  end
466
522
  end
467
523
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.2.3.pre.favorites.1
4
+ version: 15.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-25 00:00:00.000000000 Z
11
+ date: 2018-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -431,13 +431,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
431
431
  version: 2.3.0
432
432
  required_rubygems_version: !ruby/object:Gem::Requirement
433
433
  requirements:
434
- - - ">"
434
+ - - ">="
435
435
  - !ruby/object:Gem::Version
436
- version: 1.3.1
436
+ version: '0'
437
437
  requirements:
438
438
  - Ruby >= 2.3.0
439
439
  rubyforge_project:
440
- rubygems_version: 2.5.1
440
+ rubygems_version: 2.6.14
441
441
  signing_key:
442
442
  specification_version: 4
443
443
  summary: Rails gem providing an easy, active-record-like interface for http json services