lhs 21.2.0 → 21.2.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 +4 -4
- data/lib/lhs/concerns/record/request.rb +16 -6
- data/lib/lhs/version.rb +1 -1
- data/spec/record/includes_spec.rb +59 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdee54df382d303ac6c2df71e4dfb3ce6816d098578fc1919262b2daa937763c
|
4
|
+
data.tar.gz: '0340809599cfa8cb547c85dd031f8e767a644885637e77bcdc09ad011e2be617'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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
|
data/lib/lhs/version.rb
CHANGED
@@ -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
|