lhs 19.5.0 → 19.6.0
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/README.md +38 -0
- data/friday.yml +2 -0
- data/lib/lhs.rb +2 -0
- data/lib/lhs/concerns/record/pagination.rb +6 -1
- data/lib/lhs/concerns/record/request.rb +25 -4
- data/lib/lhs/pagination/base.rb +9 -1
- data/lib/lhs/pagination/link.rb +21 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/pagination/link/current_page_spec.rb +19 -0
- data/spec/pagination/link/pages_left_spec.rb +36 -0
- data/spec/pagination/link/parallel_spec.rb +19 -0
- data/spec/pagination/link/total_spec.rb +46 -0
- data/spec/pagination/{pages_left_spec.rb → offset/pages_left_spec.rb} +0 -7
- data/spec/record/includes_all_spec.rb +72 -4
- data/spec/record/paginatable_collection_spec.rb +73 -0
- data/spec/record/tracing_spec.rb +0 -1
- metadata +14 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27484e8b67d86a110c1e880e53d42f605646754cd0fe7b52369a5dcc381f3d97
|
4
|
+
data.tar.gz: b359ed2464317011e78586fbc1804812b269fa6da8f053028d8bbca946acac18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 779e482a39d72b249c30ed2ab82ab9c26d5fcd922c5d8149bfc1d0bd2838daec87ad1ff170503f532962f6bb07e9806c932c00c630ecae77d4af600aa45f2e6c
|
7
|
+
data.tar.gz: 85ba8a79e1e6b0c8f66fd7c4592636140f61d8a12b1b2d86333bb5ef86f2a2f48a44aeeae51732e1fd54752bcd90456f6951539a59cc5c4f94f7d2a7a875bb95
|
data/README.md
CHANGED
@@ -1230,6 +1230,44 @@ In parallel:
|
|
1230
1230
|
GET https://service.example.com/records?limit=100&startAt=201
|
1231
1231
|
```
|
1232
1232
|
|
1233
|
+
##### Pagination strategy: link
|
1234
|
+
|
1235
|
+
The `link` strategy continuously follows in-response embedded links to following pages until the last page is reached (indicated by no more `next` link).
|
1236
|
+
|
1237
|
+
*WARNING*
|
1238
|
+
|
1239
|
+
Loading all pages from a resource paginated with links only can result in very poor performance, as pages can only be loaded sequentially!
|
1240
|
+
|
1241
|
+
```ruby
|
1242
|
+
# app/models/record.rb
|
1243
|
+
|
1244
|
+
class Search < LHS::Record
|
1245
|
+
configuration pagination_strategy: 'link'
|
1246
|
+
|
1247
|
+
endpoint '{+service}/search'
|
1248
|
+
end
|
1249
|
+
```
|
1250
|
+
|
1251
|
+
```ruby
|
1252
|
+
# app/controllers/some_controller.rb
|
1253
|
+
|
1254
|
+
Record.all
|
1255
|
+
|
1256
|
+
```
|
1257
|
+
```
|
1258
|
+
GET https://service.example.com/records?limit=100
|
1259
|
+
{
|
1260
|
+
items: [{...}, ...],
|
1261
|
+
limit: 100,
|
1262
|
+
next: {
|
1263
|
+
href: 'https://service.example.com/records?from_record_id=p62qM5p0NK_qryO52Ze-eg&limit=100'
|
1264
|
+
}
|
1265
|
+
}
|
1266
|
+
Sequentially:
|
1267
|
+
GET https://service.example.com/records?from_record_id=p62qM5p0NK_qryO52Ze-eg&limit=100
|
1268
|
+
GET https://service.example.com/records?from_record_id=xcaoXBmuMyFFEcFDSgNgDQ&limit=100
|
1269
|
+
```
|
1270
|
+
|
1233
1271
|
#### Pagination keys
|
1234
1272
|
|
1235
1273
|
##### limit_key
|
data/friday.yml
ADDED
data/lib/lhs.rb
CHANGED
@@ -24,6 +24,8 @@ class LHS::Record
|
|
24
24
|
LHS::Pagination::Page
|
25
25
|
when :start
|
26
26
|
LHS::Pagination::Start
|
27
|
+
when :link
|
28
|
+
LHS::Pagination::Link
|
27
29
|
else
|
28
30
|
LHS::Pagination::Offset
|
29
31
|
end
|
@@ -35,7 +37,10 @@ class LHS::Record
|
|
35
37
|
|
36
38
|
# Checks if given raw is paginated or not
|
37
39
|
def paginated?(raw)
|
38
|
-
|
40
|
+
raw.is_a?(Hash) && (
|
41
|
+
raw.dig(*total_key).present? ||
|
42
|
+
raw.dig(*limit_key(:body)).present?
|
43
|
+
)
|
39
44
|
end
|
40
45
|
end
|
41
46
|
end
|
@@ -277,8 +277,16 @@ class LHS::Record
|
|
277
277
|
def load_and_merge_paginated_collection!(data, options)
|
278
278
|
set_nested_data(data._raw, limit_key(:body), data.length) if data._raw.dig(*limit_key(:body)).blank? && !data.length.zero?
|
279
279
|
pagination = data._record.pagination(data)
|
280
|
-
return data
|
280
|
+
return data unless pagination.pages_left?
|
281
281
|
record = data._record
|
282
|
+
if pagination.parallel?
|
283
|
+
load_and_merge_parallel_requests!(record, data, pagination, options)
|
284
|
+
else
|
285
|
+
load_and_merge_sequential_requests!(record, data, options, data._raw.dig(:next, :href), pagination)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def load_and_merge_parallel_requests!(record, data, pagination, options)
|
282
290
|
record.request(
|
283
291
|
options_for_next_batch(record, pagination, options)
|
284
292
|
).each do |batch_data|
|
@@ -286,13 +294,24 @@ class LHS::Record
|
|
286
294
|
end
|
287
295
|
end
|
288
296
|
|
297
|
+
def load_and_merge_sequential_requests!(record, data, options, next_link, pagination)
|
298
|
+
warn "[WARNING] You are loading all pages from a resource paginated with links only. As this is performed sequentially, it can result in very poor performance! (https://github.com/local-ch/lhs#pagination-strategy-link)."
|
299
|
+
while next_link.present?
|
300
|
+
page_data = record.request(
|
301
|
+
options.except(:all).merge(url: next_link)
|
302
|
+
)
|
303
|
+
next_link = page_data._raw.dig(:next, :href)
|
304
|
+
merge_batch_data_with_parent!(page_data, data, pagination)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
289
308
|
def load_and_merge_set_of_paginated_collections!(data, options)
|
290
309
|
options_for_next_batch = []
|
291
310
|
options.each_with_index do |element, index|
|
292
311
|
next if element.nil?
|
293
312
|
record = data[index]._record
|
294
313
|
pagination = record.pagination(data[index])
|
295
|
-
next
|
314
|
+
next unless pagination.pages_left?
|
296
315
|
options_for_next_batch.push(
|
297
316
|
options_for_next_batch(record, pagination, options[index]).tap do |options|
|
298
317
|
options.each do |option|
|
@@ -345,7 +364,8 @@ class LHS::Record
|
|
345
364
|
# paginates itself to ensure all records are fetched
|
346
365
|
def load_all_included!(record, options)
|
347
366
|
data = record.request(options)
|
348
|
-
|
367
|
+
pagination = data._record.pagination(data)
|
368
|
+
load_and_merge_remaining_objects!(data: data, options: options) if pagination.parallel?
|
349
369
|
data
|
350
370
|
end
|
351
371
|
|
@@ -386,8 +406,9 @@ class LHS::Record
|
|
386
406
|
options || {}
|
387
407
|
end
|
388
408
|
|
389
|
-
def merge_batch_data_with_parent!(batch_data, parent_data)
|
409
|
+
def merge_batch_data_with_parent!(batch_data, parent_data, pagination = nil)
|
390
410
|
parent_data.concat(input: parent_data._raw, items: batch_data.raw_items, record: self)
|
411
|
+
return if pagination.present? && pagination.is_a?(LHS::Pagination::Link)
|
391
412
|
[limit_key(:body), total_key, pagination_key(:body)].each do |pagination_attribute|
|
392
413
|
set_nested_data(
|
393
414
|
parent_data._raw,
|
data/lib/lhs/pagination/base.rb
CHANGED
@@ -35,12 +35,16 @@ module LHS::Pagination
|
|
35
35
|
total_pages - current_page
|
36
36
|
end
|
37
37
|
|
38
|
+
def pages_left?
|
39
|
+
pages_left > 0
|
40
|
+
end
|
41
|
+
|
38
42
|
def next_offset(_step = 1)
|
39
43
|
raise 'to be implemented in subclass'
|
40
44
|
end
|
41
45
|
|
42
46
|
def current_page
|
43
|
-
|
47
|
+
# should be implemented in subclass (optional)
|
44
48
|
end
|
45
49
|
|
46
50
|
def first_page
|
@@ -51,6 +55,10 @@ module LHS::Pagination
|
|
51
55
|
total_pages
|
52
56
|
end
|
53
57
|
|
58
|
+
def parallel?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
54
62
|
def next?
|
55
63
|
data._raw[:next].present?
|
56
64
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class LHS::Pagination::Link < LHS::Pagination::Base
|
4
|
+
def total
|
5
|
+
data._raw.dig(*_record.items_key).count || 0
|
6
|
+
end
|
7
|
+
|
8
|
+
alias count total
|
9
|
+
|
10
|
+
def pages_left
|
11
|
+
pages_left? ? 1 : 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def pages_left?
|
15
|
+
data._raw[:next].present?
|
16
|
+
end
|
17
|
+
|
18
|
+
def parallel?
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
describe LHS::Record do
|
6
|
+
let(:data_hash) do
|
7
|
+
{ items: 98.times.map { { foo: 'bar' } }, limit: 10, next: { href: 'http://example.com/users?from_user_id=100&limit=100' } }
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:data) do
|
11
|
+
LHS::Data.new(data_hash, nil, Record)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:pagination) { LHS::Pagination::Link.new(data) }
|
15
|
+
|
16
|
+
it 'responds to parallel?' do
|
17
|
+
expect(pagination.current_page).to be nil
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
describe LHS::Record do
|
6
|
+
let(:next_parameter) do
|
7
|
+
{ next: { href: 'http://example.com/users?from_user_id=100&limit=100' } }
|
8
|
+
end
|
9
|
+
let(:data_hash) { { items: 98.times.map { { foo: 'bar' } }, limit: 10 }.merge(next_parameter) }
|
10
|
+
|
11
|
+
let(:data) do
|
12
|
+
LHS::Data.new(data_hash, nil, Record)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:pagination) { LHS::Pagination::Link.new(data) }
|
16
|
+
|
17
|
+
it 'responds to pages_left' do
|
18
|
+
expect(pagination.pages_left).to eq(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'responds to pages_left?' do
|
22
|
+
expect(pagination.pages_left?).to be true
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when there is no next' do
|
26
|
+
let(:next_parameter) { {} }
|
27
|
+
|
28
|
+
it 'responds to pages_left' do
|
29
|
+
expect(pagination.pages_left).to eq(0)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'responds to pages_left?' do
|
33
|
+
expect(pagination.pages_left?).to be false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
describe LHS::Record do
|
6
|
+
let(:data_hash) do
|
7
|
+
{ items: 98.times.map { { foo: 'bar' } }, limit: 10, next: { href: 'http://example.com/users?from_user_id=100&limit=100' } }
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:data) do
|
11
|
+
LHS::Data.new(data_hash, nil, Record)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:pagination) { LHS::Pagination::Link.new(data) }
|
15
|
+
|
16
|
+
it 'responds to parallel?' do
|
17
|
+
expect(pagination.parallel?).to be false
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
require 'webrick'
|
5
|
+
|
6
|
+
describe LHS::Record do
|
7
|
+
|
8
|
+
before do
|
9
|
+
class User < LHS::Record
|
10
|
+
endpoint 'http://example.com/users'
|
11
|
+
configuration(
|
12
|
+
limit_key: 'limit',
|
13
|
+
items_key: 'items',
|
14
|
+
pagination_strategy: 'link'
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'explicit pagination parameters for retrieving pages' do
|
20
|
+
it 'uses explicit parameters when retrieving pages' do
|
21
|
+
stub_request(:get, "http://example.com/users?limit=100")
|
22
|
+
.to_return(body: {
|
23
|
+
items: 100.times.map { |_| { name: WEBrick::Utils.random_string(10) } },
|
24
|
+
limit: 100,
|
25
|
+
next: { href: 'http://example.com/users?from_user_id=100&limit=100' }
|
26
|
+
}.to_json)
|
27
|
+
|
28
|
+
stub_request(:get, 'http://example.com/users?from_user_id=100&limit=100')
|
29
|
+
.to_return(body: {
|
30
|
+
items: 3.times.map { |_| { name: WEBrick::Utils.random_string(10) } },
|
31
|
+
limit: 100,
|
32
|
+
next: { href: 'http://example.com/users?from_user_id=200&limit=100' }
|
33
|
+
}.to_json)
|
34
|
+
|
35
|
+
stub_request(:get, 'http://example.com/users?from_user_id=200&limit=100')
|
36
|
+
.to_return(body: {
|
37
|
+
items: [],
|
38
|
+
limit: 100
|
39
|
+
}.to_json)
|
40
|
+
|
41
|
+
users = User.all.fetch
|
42
|
+
expect(users.total).to eq 103
|
43
|
+
expect(users.count).to eq 103
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -12,12 +12,6 @@ describe LHS::Record do
|
|
12
12
|
|
13
13
|
let(:pagination) { LHS::Pagination::Offset.new(data) }
|
14
14
|
|
15
|
-
before do
|
16
|
-
class Record < LHS::Record
|
17
|
-
endpoint '{+datastore}/v2/data'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
15
|
it 'responds to pages_left' do
|
22
16
|
expect(pagination.pages_left).to eq(9)
|
23
17
|
end
|
@@ -26,7 +20,6 @@ describe LHS::Record do
|
|
26
20
|
let(:offset) { nil }
|
27
21
|
|
28
22
|
it 'responds to pages_left' do
|
29
|
-
# TODO i now set the nil offset to zero. Is this ok or wrong?
|
30
23
|
expect(pagination.pages_left).to eq(9)
|
31
24
|
end
|
32
25
|
end
|
@@ -8,20 +8,33 @@ describe LHS::Record do
|
|
8
8
|
class Customer < LHS::Record
|
9
9
|
endpoint 'http://datastore/customers/{id}'
|
10
10
|
end
|
11
|
+
|
12
|
+
class User < LHS::Record
|
13
|
+
configuration pagination_strategy: 'link'
|
14
|
+
endpoint 'http://datastore/users'
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
let(:amount_of_contracts) { 33 }
|
14
19
|
let(:amount_of_products) { 22 }
|
20
|
+
let(:amount_of_users_1st_page) { 10 }
|
21
|
+
let(:amount_of_users_2nd_page) { 3 }
|
22
|
+
let(:amount_of_users) { amount_of_users_1st_page + amount_of_users_2nd_page }
|
15
23
|
|
16
24
|
let!(:customer_request) do
|
17
25
|
stub_request(:get, 'http://datastore/customers/1')
|
18
26
|
.to_return(
|
19
27
|
body: {
|
20
|
-
contracts: { href: 'http://datastore/customers/1/contracts' }
|
28
|
+
contracts: { href: 'http://datastore/customers/1/contracts' },
|
29
|
+
users: { href: 'http://datastore/users?limit=10' }
|
21
30
|
}.to_json
|
22
31
|
)
|
23
32
|
end
|
24
33
|
|
34
|
+
#
|
35
|
+
# Contracts
|
36
|
+
#
|
37
|
+
|
25
38
|
let!(:contracts_request) do
|
26
39
|
stub_request(:get, "http://datastore/customers/1/contracts?limit=100")
|
27
40
|
.to_return(
|
@@ -66,6 +79,10 @@ describe LHS::Record do
|
|
66
79
|
additional_contracts_request(30, 3)
|
67
80
|
end
|
68
81
|
|
82
|
+
#
|
83
|
+
# Products
|
84
|
+
#
|
85
|
+
|
69
86
|
let!(:products_request) do
|
70
87
|
stub_request(:get, "http://datastore/products?limit=100")
|
71
88
|
.to_return(
|
@@ -102,10 +119,58 @@ describe LHS::Record do
|
|
102
119
|
additional_products_request(20, 2)
|
103
120
|
end
|
104
121
|
|
122
|
+
#
|
123
|
+
# Users
|
124
|
+
#
|
125
|
+
|
126
|
+
let!(:users_request) do
|
127
|
+
stub_request(:get, 'http://datastore/users?limit=10')
|
128
|
+
.to_return(
|
129
|
+
body: {
|
130
|
+
items: amount_of_users_1st_page.times.map do
|
131
|
+
{ name: 'Hans Muster' }
|
132
|
+
end,
|
133
|
+
limit: 10,
|
134
|
+
next: { href: 'http://datastore/users?for_user_id=10&limit=10' }
|
135
|
+
}.to_json
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
let!(:users_request_page_2) do
|
140
|
+
stub_request(:get, 'http://datastore/users?for_user_id=10&limit=10')
|
141
|
+
.to_return(
|
142
|
+
body: {
|
143
|
+
items: amount_of_users_2nd_page.times.map do
|
144
|
+
{ name: 'Lisa Müller' }
|
145
|
+
end,
|
146
|
+
limit: 10,
|
147
|
+
next: { href: 'http://datastore/users?for_user_id=13&limit=10' }
|
148
|
+
}.to_json
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
let!(:users_request_page_3) do
|
153
|
+
stub_request(:get, 'http://datastore/users?for_user_id=13&limit=10')
|
154
|
+
.to_return(
|
155
|
+
body: {
|
156
|
+
items: [],
|
157
|
+
limit: 10
|
158
|
+
}.to_json
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
105
162
|
it 'includes all linked business objects no matter pagination' do
|
106
|
-
customer =
|
107
|
-
|
108
|
-
|
163
|
+
customer = nil
|
164
|
+
|
165
|
+
expect(lambda do
|
166
|
+
customer = Customer
|
167
|
+
.includes_all(:users, contracts: :products)
|
168
|
+
.find(1)
|
169
|
+
end).to output(
|
170
|
+
%r{\[WARNING\] You are loading all pages from a resource paginated with links only. As this is performed sequentially, it can result in very poor performance! \(https://github.com/local-ch/lhs#pagination-strategy-link\).}
|
171
|
+
).to_stderr
|
172
|
+
|
173
|
+
expect(customer.users.length).to eq amount_of_users
|
109
174
|
expect(customer.contracts.length).to eq amount_of_contracts
|
110
175
|
expect(customer.contracts.first.products.length).to eq amount_of_products
|
111
176
|
expect(customer_request).to have_been_requested.at_least_once
|
@@ -116,6 +181,9 @@ describe LHS::Record do
|
|
116
181
|
expect(products_request).to have_been_requested.at_least_once
|
117
182
|
expect(products_request_page_2).to have_been_requested.at_least_once
|
118
183
|
expect(products_request_page_3).to have_been_requested.at_least_once
|
184
|
+
expect(users_request).to have_been_requested.at_least_once
|
185
|
+
expect(users_request_page_2).to have_been_requested.at_least_once
|
186
|
+
expect(users_request_page_3).to have_been_requested.at_least_once
|
119
187
|
end
|
120
188
|
|
121
189
|
context 'links already contain pagination parameters' do
|
@@ -284,4 +284,77 @@ describe LHS::Record do
|
|
284
284
|
expect(all.last).to eq 223
|
285
285
|
end
|
286
286
|
end
|
287
|
+
|
288
|
+
context 'pagination using links' do
|
289
|
+
before do
|
290
|
+
class Record < LHS::Record
|
291
|
+
configuration pagination_strategy: 'link'
|
292
|
+
endpoint '{+datastore}/feedbacks'
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'fetches all records from the backend' do
|
297
|
+
stub_request(:get, "#{datastore}/feedbacks?limit=100")
|
298
|
+
.to_return(
|
299
|
+
status: 200,
|
300
|
+
body: { items: (1..100).to_a, limit: 100, next: { href: "#{datastore}/feedbacks?limit=100&cursor=x" } }.to_json
|
301
|
+
)
|
302
|
+
stub_request(:get, "#{datastore}/feedbacks?limit=100&cursor=x")
|
303
|
+
.to_return(
|
304
|
+
status: 200,
|
305
|
+
body: { items: (101..200).to_a, limit: 100, next: { href: "#{datastore}/feedbacks?limit=100&cursor=y" } }.to_json
|
306
|
+
)
|
307
|
+
stub_request(:get, "#{datastore}/feedbacks?limit=100&cursor=y")
|
308
|
+
.to_return(
|
309
|
+
status: 200,
|
310
|
+
body: { items: (201..300).to_a, limit: 100, next: { href: "#{datastore}/feedbacks?limit=100&cursor=z" } }.to_json
|
311
|
+
)
|
312
|
+
stub_request(:get, "#{datastore}/feedbacks?limit=100&cursor=z")
|
313
|
+
.to_return(
|
314
|
+
status: 200,
|
315
|
+
body: { items: [], limit: 100 }.to_json
|
316
|
+
)
|
317
|
+
all = Record.all
|
318
|
+
|
319
|
+
expect(all).to be_kind_of Record
|
320
|
+
expect(all._data._proxy).to be_kind_of LHS::Collection
|
321
|
+
expect(all.count).to eq 300
|
322
|
+
expect(all.last).to eq 300
|
323
|
+
end
|
324
|
+
|
325
|
+
it 'fetches all, also if there is a rest and the total is not divideable trough the limit' do
|
326
|
+
stub_request(:get, "#{datastore}/feedbacks?limit=100")
|
327
|
+
.to_return(
|
328
|
+
status: 200,
|
329
|
+
body: { items: (1..100).to_a, limit: 100, next: { href: "#{datastore}/feedbacks?limit=100&cursor=x" } }.to_json
|
330
|
+
)
|
331
|
+
stub_request(:get, "#{datastore}/feedbacks?limit=100&cursor=x")
|
332
|
+
.to_return(
|
333
|
+
status: 200,
|
334
|
+
body: { items: (101..200).to_a, limit: 100, next: { href: "#{datastore}/feedbacks?limit=100&cursor=y" } }.to_json
|
335
|
+
)
|
336
|
+
stub_request(:get, "#{datastore}/feedbacks?limit=100&cursor=y")
|
337
|
+
.to_return(
|
338
|
+
status: 200,
|
339
|
+
body: { items: (201..300).to_a, limit: 100, next: { href: "#{datastore}/feedbacks?limit=100&cursor=z" } }.to_json
|
340
|
+
)
|
341
|
+
stub_request(:get, "#{datastore}/feedbacks?limit=100&cursor=z")
|
342
|
+
.to_return(
|
343
|
+
status: 200,
|
344
|
+
body: { items: [301], limit: 100 }.to_json
|
345
|
+
)
|
346
|
+
|
347
|
+
all = nil
|
348
|
+
expect(lambda do
|
349
|
+
all = Record.all.fetch
|
350
|
+
end).to output(
|
351
|
+
%r{\[WARNING\] You are loading all pages from a resource paginated with links only. As this is performed sequentially, it can result in very poor performance! \(https://github.com/local-ch/lhs#pagination-strategy-link\).}
|
352
|
+
).to_stderr
|
353
|
+
|
354
|
+
expect(all).to be_kind_of Record
|
355
|
+
expect(all._data._proxy).to be_kind_of LHS::Collection
|
356
|
+
expect(all.count).to eq 301
|
357
|
+
expect(all.last).to eq 301
|
358
|
+
end
|
359
|
+
end
|
287
360
|
end
|
data/spec/record/tracing_spec.rb
CHANGED
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: 19.
|
4
|
+
version: 19.6.0
|
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: 2019-07-
|
11
|
+
date: 2019-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- cider-ci/task_components/rspec.yml
|
216
216
|
- cider-ci/task_components/rubocop.yml
|
217
217
|
- cider-ci/task_components/ruby.yml
|
218
|
+
- friday.yml
|
218
219
|
- lhs.gemspec
|
219
220
|
- lib/lhs.rb
|
220
221
|
- lib/lhs/collection.rb
|
@@ -266,6 +267,7 @@ files:
|
|
266
267
|
- lib/lhs/endpoint.rb
|
267
268
|
- lib/lhs/item.rb
|
268
269
|
- lib/lhs/pagination/base.rb
|
270
|
+
- lib/lhs/pagination/link.rb
|
269
271
|
- lib/lhs/pagination/offset.rb
|
270
272
|
- lib/lhs/pagination/page.rb
|
271
273
|
- lib/lhs/pagination/start.rb
|
@@ -380,7 +382,11 @@ files:
|
|
380
382
|
- spec/item/validation_spec.rb
|
381
383
|
- spec/item/warning_codes_spec.rb
|
382
384
|
- spec/item/warnings_spec.rb
|
383
|
-
- spec/pagination/
|
385
|
+
- spec/pagination/link/current_page_spec.rb
|
386
|
+
- spec/pagination/link/pages_left_spec.rb
|
387
|
+
- spec/pagination/link/parallel_spec.rb
|
388
|
+
- spec/pagination/link/total_spec.rb
|
389
|
+
- spec/pagination/offset/pages_left_spec.rb
|
384
390
|
- spec/pagination/parameters_spec.rb
|
385
391
|
- spec/proxy/create_sub_resource_spec.rb
|
386
392
|
- spec/proxy/load_spec.rb
|
@@ -584,7 +590,11 @@ test_files:
|
|
584
590
|
- spec/item/validation_spec.rb
|
585
591
|
- spec/item/warning_codes_spec.rb
|
586
592
|
- spec/item/warnings_spec.rb
|
587
|
-
- spec/pagination/
|
593
|
+
- spec/pagination/link/current_page_spec.rb
|
594
|
+
- spec/pagination/link/pages_left_spec.rb
|
595
|
+
- spec/pagination/link/parallel_spec.rb
|
596
|
+
- spec/pagination/link/total_spec.rb
|
597
|
+
- spec/pagination/offset/pages_left_spec.rb
|
588
598
|
- spec/pagination/parameters_spec.rb
|
589
599
|
- spec/proxy/create_sub_resource_spec.rb
|
590
600
|
- spec/proxy/load_spec.rb
|