lhs 11.3.1 → 11.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhs/concerns/record/request.rb +10 -10
- data/lib/lhs/version.rb +1 -1
- data/spec/record/includes_all_spec.rb +78 -0
- data/spec/record/includes_spec.rb +26 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bbf841e955ed23fe6c7efbf8f8fe7b05fc35538
|
4
|
+
data.tar.gz: d331ac41f574be37f783b10ff7c53fe43c592a8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c0a3fee58998e8c51a25c16702a17b20cec97498979863040b2120d51a776e6333733c807e1940105f24e15b987d2d84e50a50c7fbf4846e1aff472b1e840d2
|
7
|
+
data.tar.gz: 6cb8b54105e3579b76e3ff9d9a26c3d738a85e73eb4ded2a93343a176b3231a99fc88bb7f39cc956faf3375bbc7bf46edd8b51088632ad7eb6cacb3aab8926d1
|
@@ -87,16 +87,16 @@ class LHS::Record
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def extend_base_collection!(data, addition, key)
|
90
|
-
data.
|
91
|
-
|
92
|
-
|
93
|
-
next if link.blank?
|
94
|
-
link.merge_raw!(addition[i]) && next if !link.collection?
|
95
|
-
|
96
|
-
link.each_with_index do |item, j|
|
97
|
-
item.merge_raw!(addition[i + j]) if item.present?
|
98
|
-
end
|
90
|
+
data.map do |item|
|
91
|
+
item_raw = item._raw[key]
|
92
|
+
item_raw.blank? ? [nil] : item_raw
|
99
93
|
end
|
94
|
+
.flatten
|
95
|
+
.each_with_index do |item, index|
|
96
|
+
item_addition = addition[index]
|
97
|
+
next if item_addition.nil? || item.nil?
|
98
|
+
item.merge! item_addition._raw
|
99
|
+
end
|
100
100
|
end
|
101
101
|
|
102
102
|
def extend_base_array!(data, addition, key)
|
@@ -301,7 +301,7 @@ class LHS::Record
|
|
301
301
|
# When including all resources on one level, don't forward :includes & :references
|
302
302
|
# as we have to fetch all resources on this level first, before we continue_including
|
303
303
|
def prepare_option_for_include_all_request!(option)
|
304
|
-
return option if option.
|
304
|
+
return option if option.blank? || option[:url].nil?
|
305
305
|
uri = parse_uri(option[:url], option)
|
306
306
|
get_params = Rack::Utils.parse_nested_query(uri.query)
|
307
307
|
.symbolize_keys
|
data/lib/lhs/version.rb
CHANGED
@@ -260,5 +260,83 @@ describe LHS::Record do
|
|
260
260
|
expect(customer.contracts.first.entry.name).to eq 'Casa Ferlin'
|
261
261
|
end
|
262
262
|
end
|
263
|
+
|
264
|
+
context 'includes all for parallel loaded ids' do
|
265
|
+
before(:each) do
|
266
|
+
class Place < LHS::Record
|
267
|
+
endpoint 'http://datastore/places/:id'
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
let!(:place_request_1) do
|
272
|
+
stub_request(:get, %r{http://datastore/places/1})
|
273
|
+
.to_return(
|
274
|
+
body: {
|
275
|
+
category_relations: [
|
276
|
+
{ href: 'http://datastore/category_relations/1' },
|
277
|
+
{ href: 'http://datastore/category_relations/2' }
|
278
|
+
]
|
279
|
+
}.to_json
|
280
|
+
)
|
281
|
+
end
|
282
|
+
|
283
|
+
let!(:place_request_2) do
|
284
|
+
stub_request(:get, %r{http://datastore/places/2})
|
285
|
+
.to_return(
|
286
|
+
body: {
|
287
|
+
category_relations: []
|
288
|
+
}.to_json
|
289
|
+
)
|
290
|
+
end
|
291
|
+
|
292
|
+
let!(:place_request_3) do
|
293
|
+
stub_request(:get, %r{http://datastore/places/3})
|
294
|
+
.to_return(
|
295
|
+
body: {
|
296
|
+
category_relations: [
|
297
|
+
{ href: 'http://datastore/category_relations/1' },
|
298
|
+
{ href: 'http://datastore/category_relations/3' }
|
299
|
+
]
|
300
|
+
}.to_json
|
301
|
+
)
|
302
|
+
end
|
303
|
+
|
304
|
+
let!(:category_relation_request_1) do
|
305
|
+
stub_request(:get, %r{http://datastore/category_relations/1})
|
306
|
+
.to_return(
|
307
|
+
body: {
|
308
|
+
name: "Category 1"
|
309
|
+
}.to_json
|
310
|
+
)
|
311
|
+
end
|
312
|
+
|
313
|
+
let!(:category_relation_request_2) do
|
314
|
+
stub_request(:get, %r{http://datastore/category_relations/2})
|
315
|
+
.to_return(
|
316
|
+
body: {
|
317
|
+
name: "Category 2"
|
318
|
+
}.to_json
|
319
|
+
)
|
320
|
+
end
|
321
|
+
|
322
|
+
let!(:category_relation_request_3) do
|
323
|
+
stub_request(:get, %r{http://datastore/category_relations/3})
|
324
|
+
.to_return(
|
325
|
+
body: {
|
326
|
+
name: "Category 3"
|
327
|
+
}.to_json
|
328
|
+
)
|
329
|
+
end
|
330
|
+
|
331
|
+
let(:category_name) { 'Category Relation' }
|
332
|
+
|
333
|
+
it 'requests places in parallel and includes category relation' do
|
334
|
+
places = Place.includes_all(:category_relations).find(1, 2, 3)
|
335
|
+
expect(places[0].category_relations[0].name).to eq 'Category 1'
|
336
|
+
expect(places[0].category_relations[1].name).to eq 'Category 2'
|
337
|
+
expect(places[2].category_relations[0].name).to eq 'Category 1'
|
338
|
+
expect(places[2].category_relations[1].name).to eq 'Category 3'
|
339
|
+
end
|
340
|
+
end
|
263
341
|
end
|
264
342
|
end
|
@@ -264,12 +264,14 @@ describe LHS::Record do
|
|
264
264
|
end
|
265
265
|
|
266
266
|
context 'arrays' do
|
267
|
-
|
267
|
+
before(:each) do
|
268
268
|
class Place < LHS::Record
|
269
269
|
endpoint ':datastore/place'
|
270
270
|
endpoint ':datastore/place/:id'
|
271
271
|
end
|
272
|
+
end
|
272
273
|
|
274
|
+
let!(:place_request) do
|
273
275
|
stub_request(:get, "#{datastore}/place/1")
|
274
276
|
.to_return(body: {
|
275
277
|
'relations' => [
|
@@ -277,16 +279,39 @@ describe LHS::Record do
|
|
277
279
|
{ 'href' => "#{datastore}/place/relations/3" }
|
278
280
|
]
|
279
281
|
}.to_json)
|
282
|
+
end
|
280
283
|
|
284
|
+
let!(:relation_request_1) do
|
281
285
|
stub_request(:get, "#{datastore}/place/relations/2")
|
282
286
|
.to_return(body: { name: 'Category' }.to_json)
|
287
|
+
end
|
288
|
+
|
289
|
+
let!(:relation_request_2) do
|
283
290
|
stub_request(:get, "#{datastore}/place/relations/3")
|
284
291
|
.to_return(body: { name: 'ZeFrank' }.to_json)
|
292
|
+
end
|
285
293
|
|
294
|
+
it 'includes items of arrays' do
|
286
295
|
place = Place.includes(:relations).find(1)
|
287
296
|
expect(place.relations.first.name).to eq 'Category'
|
288
297
|
expect(place.relations[1].name).to eq 'ZeFrank'
|
289
298
|
end
|
299
|
+
|
300
|
+
context 'parallel with empty links' do
|
301
|
+
let!(:place_request_2) do
|
302
|
+
stub_request(:get, "#{datastore}/place/2")
|
303
|
+
.to_return(body: {
|
304
|
+
'relations' => []
|
305
|
+
}.to_json)
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'loads places in parallel and merges included data properly' do
|
309
|
+
place = Place.includes(:relations).find(2, 1)
|
310
|
+
expect(place[0].relations.empty?)
|
311
|
+
expect(place[1].relations[0].name).to eq 'Category'
|
312
|
+
expect(place[1].relations[1].name).to eq 'ZeFrank'
|
313
|
+
end
|
314
|
+
end
|
290
315
|
end
|
291
316
|
|
292
317
|
context 'empty collections' do
|
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: 11.3.
|
4
|
+
version: 11.3.2
|
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: 2017-06-
|
11
|
+
date: 2017-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|