lhs 25.0.2 → 25.0.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
  SHA256:
3
- metadata.gz: '030995aefe88b5d0494d0e7ccaa760eb2a67d8ebf728ce4aaaa8646ca5b130ef'
4
- data.tar.gz: af0e530a38ff5c816a797613506b40c996f58aea8c391ca59099d1ee6152ce00
3
+ metadata.gz: 7aa5e0e072a78d7029c968c255ac6c41e5425504b7e121fc5c205a672c59d4a7
4
+ data.tar.gz: 59a90ded930e12b7cc54842db415d5d0f2c09ade777eaccc44d9703d4bc1f46a
5
5
  SHA512:
6
- metadata.gz: 70859dbf4582c03d84edeb5aa6b750ee76a4908e2bd43e9c324b4ab8ca318da457087f2b95d3c433e570f48d2ee4a6cc691dd821830c82f86acc44f7e8ff4652
7
- data.tar.gz: ab20d6595519d82cf47a9b203f0e246062ce6d611c9997c4ae50cc3fb33c0b1378c911415df845ddbc2f714c98bc05d63c562e5364227a7ccba1a573af9f1954
6
+ metadata.gz: e953b0d8278c209f1a398298d6bbf85b91469cf285bc7c0470b401cacfce2db7b692822e7d13488c4b36c823cef1c093bc8ffb4a5d2d53ab5782765589711b07
7
+ data.tar.gz: d7124e16eca63583fb58922354253c902bbd86e0079c22e3d8b864a7a80b8acd098128a67c2e32cfe45c6ed28d19158def5a063fec174bdba364435b11054d92
@@ -14,7 +14,7 @@ class LHS::Collection < LHS::Proxy
14
14
 
15
15
  METHOD_NAMES_EXLCUDED_FROM_WRAPPING = %w(to_a to_ary map).freeze
16
16
 
17
- delegate :select, :length, :size, to: :_collection
17
+ delegate :select, :length, :size, :insert, to: :_collection
18
18
  delegate :_record, :_raw, to: :_data
19
19
  delegate :limit, :count, :total, :offset, :current_page, :start,
20
20
  :next?, :previous?, to: :_pagination
@@ -14,7 +14,7 @@ class LHS::Collection < LHS::Proxy
14
14
 
15
15
  attr_accessor :raw
16
16
  delegate :length, :size, :first, :last, :sample, :[], :present?, :blank?, :empty?,
17
- :<<, :push, to: :raw
17
+ :<<, :push, :insert, to: :raw
18
18
 
19
19
  def initialize(raw, parent, record)
20
20
  self.raw = raw
@@ -29,7 +29,10 @@ class LHS::Record
29
29
  if options.is_a?(Hash)
30
30
  options.deep_merge(LHS::OptionBlocks::CurrentOptionBlock.options)
31
31
  elsif options.is_a?(Array)
32
- options.map { |option| option.deep_merge(LHS::OptionBlocks::CurrentOptionBlock.options) }
32
+ options.map do |option|
33
+ return LHS::OptionBlocks::CurrentOptionBlock.options unless option
34
+ option.deep_merge(LHS::OptionBlocks::CurrentOptionBlock.options)
35
+ end
33
36
  end
34
37
  end
35
38
 
@@ -118,7 +121,7 @@ class LHS::Record
118
121
  else
119
122
  options = options_for_data(data, included)
120
123
  options = extend_with_reference(options, reference)
121
- addition = load_include(options, data, sub_includes, reference)
124
+ addition = load_existing_includes(options, data, sub_includes, reference)
122
125
  data.extend!(addition, included)
123
126
  expand_addition!(data, included, reference) unless expanded_data?(addition)
124
127
  end
@@ -277,6 +280,21 @@ class LHS::Record
277
280
  end
278
281
  end
279
282
 
283
+ def load_existing_includes(options, data, sub_includes, references)
284
+ if data.collection? && data.any?(&:blank?)
285
+ # filter only existing items
286
+ loaded_includes = load_include(options.compact, data.compact, sub_includes, references)
287
+ # fill up skipped items before returning
288
+ data.each_with_index do |item, index|
289
+ next if item.present?
290
+ loaded_includes.insert(index, {})
291
+ end
292
+ loaded_includes
293
+ else
294
+ load_include(options, data, sub_includes, references)
295
+ end
296
+ end
297
+
280
298
  # Load additional resources that are requested with include
281
299
  def load_include(options, _data, sub_includes, references)
282
300
  record = record_for_options(options) || self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHS
4
- VERSION = '25.0.2'
4
+ VERSION = '25.0.3'
5
5
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHS::Record do
6
+
7
+ context 'merge request options ' do
8
+ before do
9
+ class Record < LHS::Record
10
+ endpoint 'http://records/{id}'
11
+ end
12
+
13
+ stub_request(:get, 'http://records/1')
14
+ .to_return(body: {
15
+ place_attributes: [
16
+ { href: 'https://attributes/bar' },
17
+ { href: 'https://attributes/restaurant' },
18
+ { href: 'https://attributes/cafe' }
19
+ ]
20
+ }.to_json)
21
+
22
+ stub_request(:get, "https://attributes/restaurant?limit=100")
23
+ .to_return(body: {}.to_json)
24
+ stub_request(:get, "https://attributes/restaurant")
25
+ .to_return(body: {}.to_json)
26
+ stub_request(:get, "https://attributes/bar?limit=100")
27
+ .to_return(body: {
28
+ group: {
29
+ href: 'https://group/general'
30
+ }
31
+ }.to_json)
32
+ stub_request(:get, "https://attributes/cafe?limit=100")
33
+ .to_return(body: {
34
+ group: {
35
+ href: 'https://group/general'
36
+ }
37
+ }.to_json)
38
+ stub_request(:get, "https://group/general?limit=100&status=active")
39
+ .to_return(body: {
40
+ name: 'General'
41
+ }.to_json)
42
+ end
43
+
44
+ context 'missing referenced options due to none existance of include' do
45
+
46
+ it 'does not raise when trying to merge options with the options block' do
47
+ LHS.options(throttle: { break: '80%' }) do
48
+ record = Record
49
+ .references(place_attributes: { group: { params: { status: 'active' } } })
50
+ .includes([{ place_attributes: :group }])
51
+ .find(1)
52
+ expect(record.place_attributes[0].group.name).to eq 'General'
53
+ expect(record.place_attributes[1].group).to eq nil
54
+ expect(record.place_attributes[2].group.name).to eq 'General'
55
+ end
56
+ end
57
+ end
58
+ end
59
+ 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: 25.0.2
4
+ version: 25.0.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: 2020-10-30 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -507,6 +507,7 @@ files:
507
507
  - spec/record/immutable_chains_spec.rb
508
508
  - spec/record/includes_expanded_spec.rb
509
509
  - spec/record/includes_first_page_spec.rb
510
+ - spec/record/includes_missing_spec.rb
510
511
  - spec/record/includes_spec.rb
511
512
  - spec/record/includes_warning_spec.rb
512
513
  - spec/record/item_key_spec.rb
@@ -738,6 +739,7 @@ test_files:
738
739
  - spec/record/immutable_chains_spec.rb
739
740
  - spec/record/includes_expanded_spec.rb
740
741
  - spec/record/includes_first_page_spec.rb
742
+ - spec/record/includes_missing_spec.rb
741
743
  - spec/record/includes_spec.rb
742
744
  - spec/record/includes_warning_spec.rb
743
745
  - spec/record/item_key_spec.rb