lhs 15.2.1 → 15.2.2.pre.favorites.1

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: b22ab9cad00592e285064f9e5423a0068cf0924c
4
- data.tar.gz: '079d61d3f7a12423f689e64de210bb67243ec239'
3
+ metadata.gz: 0aee048c57cc0d33d0460f7b1887576f387896bd
4
+ data.tar.gz: 9bcbc261eacb20732cf29313dc0757b2f822c903
5
5
  SHA512:
6
- metadata.gz: 94b77bb8a7a211acdf05d62f21138442a8d0a68e75fe6bde7190f939595287f7495a51c754f8cc50013ef019ac6a996e8a838a5bd318c62bdbec70530e424458
7
- data.tar.gz: 5dc21e72c816d3437677965059f0ac9ae009e3b41f355aec95927b95b8885ba1a42b086ba685b113279bcf25a4cc75f45e12a7ee39d39e1590b3cf4d494a6e01
6
+ metadata.gz: b44c9ca36f2fd2d2154b27810394d6dfcc565e25712695bf7ef0dee0483ad4db2a8063a52e3882b0fa174060a734c66979c61725b2ce33054a7222789c72da72
7
+ data.tar.gz: 43d5d60d653ce74d32a3d7f7392f90cb98f8ebf1923ee8d5b7b4862a24600e910ab588dbc90e9ee6fcd4ad5a697a43c00f3ca04dc463212a092fc7b8000b90db
data/README.md CHANGED
@@ -53,8 +53,39 @@ class Record < LHS::Record
53
53
  end
54
54
  ```
55
55
 
56
- Please use placeholders when configuring endpoints also for hosts. Otherwise LHS will match them strictly, which can result in problems when mixing URLs containing `http`, `https` or no protocol at all.
57
- [https://github.com/local-ch/lhc/blob/master/docs/configuration.md#placeholders](LHC Placeholder Configuration)
56
+ ### Configuring endpoint hosts
57
+
58
+ Please use placeholders when configuring hosts for endpoints. Otherwise LHS will match them strictly, which can result in problems when a services dynamically returns `hrefs` and mixes `http`, `https` or no protocol at all. See: [LHC Placeholder Configuration](https://github.com/local-ch/lhc/blob/master/docs/configuration.md#placeholders)
59
+
60
+ Please DO NOT mix host placeholders with endpoints (paths), LHS need to know what part of an endpoint is a host and what part of an endpoint is a path, if you use a placeholders in your records endpoint configuration:
61
+
62
+ **DO**
63
+ ```ruby
64
+ LHC.configure do |config|
65
+ config.placeholder(:search_service, 'http://tel.search.ch')
66
+ end
67
+
68
+ class Record < LHS::Record
69
+
70
+ endpoint '{+search_service}/api/search.json'
71
+
72
+ end
73
+ ```
74
+
75
+ **DON'T**
76
+ ```ruby
77
+ LHC.configure do |config|
78
+ config.placeholder(:search_service, 'http://tel.search.ch/api/search.json')
79
+ end
80
+
81
+ class Record < LHS::Record
82
+
83
+ endpoint '{+search_service}'
84
+
85
+ end
86
+ ```
87
+
88
+ ### Endpoint clashing
58
89
 
59
90
  If you try to setup a LHS::Record with clashing endpoints it will immediately raise an exception.
60
91
 
@@ -399,7 +430,7 @@ end
399
430
  )
400
431
  ```
401
432
 
402
- See [Validation](#Validation) for handling validation errors when creating records.
433
+ See [Validation](#validation) for handling validation errors when creating records.
403
434
 
404
435
  ### Endpoint paramters and paramter injection during creation
405
436
 
@@ -842,6 +873,8 @@ or with parameters:
842
873
 
843
874
  In order to validate LHS::Records before persisting them, you can use the `valid?` (`validate` alias) method.
844
875
 
876
+ It's not recommended to validate records anywhere but with the endpoint that also provides to create them.
877
+
845
878
  The specific endpoint has to support validations without persistence. An endpoint has to be enabled (opt-in) for validations in the service configuration.
846
879
 
847
880
  ```ruby
@@ -267,14 +267,18 @@ class LHS::Record
267
267
 
268
268
  def load_and_merge_set_of_paginated_collections!(data, options)
269
269
  options_for_this_batch = []
270
- options.each_with_index do |_, index|
270
+ data_record = data._record
271
+ data = data.compact
272
+ options.compact.each_with_index do |_, index|
271
273
  record = data[index]._record
272
274
  pagination = record.pagination(data[index])
273
275
  next if pagination.pages_left.zero?
274
276
  options_for_this_batch.push(options_for_next_batch(record, pagination, options[index], data[index]))
275
277
  end
276
- data._record.request(options_for_this_batch.flatten).each do |batch_data|
277
- merge_batch_data_with_parent!(batch_data, batch_data._request.options[:parent_data])
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
278
282
  end
279
283
  end
280
284
 
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '15.2.1'
2
+ VERSION = '15.2.2-favorites.1'
3
3
  end
@@ -73,4 +73,40 @@ 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
76
112
  end
@@ -381,4 +381,88 @@ describe LHS::Record do
381
381
  expect(place.contracts.first.customer.name).to eq 'Swisscom Directories AG'
382
382
  end
383
383
  end
384
+
385
+ context 'nested includes_all' do
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
+
400
+ stub_request(:get, %r{http://datastore/favorites})
401
+ .to_return(
402
+ body: {
403
+ items: [{
404
+ href: "http://datastore/favorites/1",
405
+ place: {
406
+ href: "http://datastore/places/1"
407
+ }
408
+ }, {
409
+ href: "http://datastore/favorite/2",
410
+ place: {
411
+ href: "http://datastore/places/2"
412
+ }
413
+ }],
414
+ total: 2,
415
+ offset: 0,
416
+ limit: 100
417
+ }.to_json
418
+ )
419
+
420
+ stub_request(:get, %r{http://datastore/places/1})
421
+ .to_return(
422
+ body: {
423
+ href: "http://datastore/places/1",
424
+ name: 'Place 1',
425
+ contracts: {
426
+ href: "http://datastore/places/1/contracts"
427
+ }
428
+ }.to_json
429
+ )
430
+
431
+ stub_request(:get, %r{http://datastore/places/1/contracts})
432
+ .to_return(
433
+ body: {
434
+ items: [{
435
+ href: "http://datastore/places/1/contracts/1",
436
+ name: 'Contract 1'
437
+ }],
438
+ total: 1,
439
+ offset: 0,
440
+ limit: 10
441
+ }.to_json
442
+ )
443
+
444
+ stub_request(:get, %r{http://datastore/places/2})
445
+ .to_return(
446
+ body: {
447
+ href: "http://datastore/places/2",
448
+ name: 'Place 2'
449
+ }.to_json
450
+ )
451
+ end
452
+
453
+ it 'includes nested objects when they exist' do
454
+ favorites = Favorite.includes(:place).includes_all(place: :contracts).all
455
+
456
+ expect(favorites.first.place.name).to eq('Place 1')
457
+ expect(favorites.first.place.contracts.first.name).to eq('Contract 1')
458
+ end
459
+
460
+ it 'does not include nested objects when they are not there' do
461
+ favorites = Favorite.includes(:place).includes_all(place: :contracts).all
462
+
463
+ expect(favorites.last.place.name).to eq('Place 2')
464
+ expect(favorites.last.place.contracts).to be(nil)
465
+ end
466
+ end
467
+ end
384
468
  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.1
4
+ version: 15.2.2.pre.favorites.1
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-03-26 00:00:00.000000000 Z
11
+ date: 2018-05-25 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: '0'
436
+ version: 1.3.1
437
437
  requirements:
438
438
  - Ruby >= 2.3.0
439
439
  rubyforge_project:
440
- rubygems_version: 2.6.14
440
+ rubygems_version: 2.5.1
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