lhs 21.2.0 → 21.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6225eb173a7f2586b2a7bbeceb9a9d5c0a06c435708b9dd673a288e9e362745d
4
- data.tar.gz: 75473dc1a4fd69c7ab8392c965e9ef932a19b30e1aae2505fa902b9e713540c9
3
+ metadata.gz: cdee54df382d303ac6c2df71e4dfb3ce6816d098578fc1919262b2daa937763c
4
+ data.tar.gz: '0340809599cfa8cb547c85dd031f8e767a644885637e77bcdc09ad011e2be617'
5
5
  SHA512:
6
- metadata.gz: 897f78093924c54e3d8dce53655f075e8919c09d124cf71e676dd8b20dc3f429c623671f4697006c06d4babb07b8a18c65cd5e4c219cdc5a81955bd2d39b8fa4
7
- data.tar.gz: 7f677d03fe47a75f3ac9e87ed9a4fc7f0cf51d30402b79b100fac79f3a6cdff8e85ef902d0615d35db84ea247a9207d08c9e96badd41ea4ff01bf504d9652e60
6
+ metadata.gz: e01af57617fc98df8e61a053bb4b69a527701a29aa1cfd3b842ec1b08ca47e925702ffeedf31b019997a1693409fc00637da0dba4cc205b0cfafba0f1b2769c2
7
+ data.tar.gz: 0f7418cee11af1966be59ad017f13469aaa94a96e4214045c05434312690b5d9fad08d4193b8705844e0d5f3411a1988498b50a966cf7324c167f9062493aa8a
@@ -180,12 +180,20 @@ class LHS::Record
180
180
  end
181
181
 
182
182
  def handle_include(included, data, sub_includes = nil, reference = nil)
183
- return if data.blank? || skip_loading_includes?(data, included)
184
- options = options_for_data(data, included)
185
- options = extend_with_reference(options, reference)
186
- addition = load_include(options, data, sub_includes, reference)
187
- extend_raw_data!(data, addition, included)
188
- expand_addition!(data, included, options) if no_expanded_data?(addition)
183
+ if data.blank? || skip_loading_includes?(data, included)
184
+ handle_skip_include(included, data, sub_includes, reference)
185
+ else
186
+ options = options_for_data(data, included)
187
+ options = extend_with_reference(options, reference)
188
+ addition = load_include(options, data, sub_includes, reference)
189
+ extend_raw_data!(data, addition, included)
190
+ expand_addition!(data, included, options) if no_expanded_data?(addition)
191
+ end
192
+ end
193
+
194
+ def handle_skip_include(included, data, sub_includes = nil, reference = nil)
195
+ return if sub_includes.blank?
196
+ handle_includes(sub_includes, data[included], reference)
189
197
  end
190
198
 
191
199
  def options_for_data(data, included = nil)
@@ -238,6 +246,8 @@ class LHS::Record
238
246
  def skip_loading_includes?(data, included)
239
247
  if data.collection?
240
248
  data.to_a.none? { |item| item[included].present? }
249
+ elsif data[included].present? && data[included].item? && data[included].href.blank?
250
+ true
241
251
  else
242
252
  !data._raw.key?(included)
243
253
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHS
4
- VERSION = '21.2.0'
4
+ VERSION = '21.2.1'
5
5
  end
@@ -606,4 +606,63 @@ describe LHS::Record do
606
606
  expect(sector.services.first.key).to eq 'my_service_service_1'
607
607
  end
608
608
  end
609
+
610
+ context 'include for POST/create' do
611
+
612
+ before do
613
+ class Record < LHS::Record
614
+ endpoint 'https://records'
615
+ end
616
+ stub_request(:post, 'https://records/')
617
+ .with(body: { color: 'blue' }.to_json)
618
+ .to_return(
619
+ body: {
620
+ color: 'blue',
621
+ alternative_categories: [
622
+ { href: 'https://categories/blue' }
623
+ ]
624
+ }.to_json
625
+ )
626
+ stub_request(:get, 'https://categories/blue')
627
+ .to_return(
628
+ body: {
629
+ name: 'blue'
630
+ }.to_json
631
+ )
632
+ end
633
+
634
+ it 'includes the resources from the post response' do
635
+ records = Record.includes(:alternative_categories).create(color: 'blue')
636
+ expect(records.alternative_categories.first.name).to eq 'blue'
637
+ end
638
+ end
639
+
640
+ context 'nested within another structure' do
641
+ before do
642
+ class Place < LHS::Record
643
+ endpoint 'https://places/{id}'
644
+ end
645
+ stub_request(:get, "https://places/1")
646
+ .to_return(body: {
647
+ customer: {
648
+ salesforce: {
649
+ href: 'https://salesforce/customers/1'
650
+ }
651
+ }
652
+ }.to_json)
653
+ end
654
+
655
+ let!(:nested_request) do
656
+ stub_request(:get, "https://salesforce/customers/1")
657
+ .to_return(body: {
658
+ name: 'Steve'
659
+ }.to_json)
660
+ end
661
+
662
+ it 'includes data that has been nested in an additional structure' do
663
+ place = Place.includes(customer: :salesforce).find(1)
664
+ expect(nested_request).to have_been_requested
665
+ expect(place.customer.salesforce.name).to eq 'Steve'
666
+ end
667
+ end
609
668
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 21.2.0
4
+ version: 21.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors