lhs 4.2.0 → 4.2.1
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/all.rb +5 -1
- data/lib/lhs/concerns/record/configuration.rb +5 -5
- data/lib/lhs/pagination.rb +1 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/pagination/pages_left_spec.rb +31 -0
- data/spec/record/all_spec.rb +23 -0
- data/spec/record/paginatable_collection_spec.rb +3 -3
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97ecd71fe1e08636cbe1a790d4bd8c0787facbdd
|
4
|
+
data.tar.gz: 932f5f517996f854e619f12dbaaea58f21205c20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1768124ad016dd853334bd431d267cf45857b68d2964695b4ce0f0475f516bb01d40b3c137a4b2d93fb8d7868ccd29a830e6401953c5a4a979769feb47cd22d
|
7
|
+
data.tar.gz: b6351fc5cfee078fc8c3f64b911548e10ab72a197650f4838a666286715764a457bec28d5710229882553050bfcd84342aad3b4160fb42730adcd0d29cda4212
|
@@ -16,12 +16,16 @@ class LHS::Record
|
|
16
16
|
def all(params = {})
|
17
17
|
limit = params[limit_key] || DEFAULT_LIMIT
|
18
18
|
data = request(params: params.merge(limit_key => limit))
|
19
|
-
request_all_the_rest(data, params) if
|
19
|
+
request_all_the_rest(data, params) if paginated?(data._raw)
|
20
20
|
data._record.new(LHS::Data.new(data, nil, self))
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
def paginated?(raw)
|
26
|
+
raw.is_a?(Hash) && raw[total_key] && raw[pagination_key]
|
27
|
+
end
|
28
|
+
|
25
29
|
def all_items_from(data)
|
26
30
|
if data._raw.is_a?(Array)
|
27
31
|
data._raw
|
@@ -15,25 +15,25 @@ class LHS::Record
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def items_key
|
18
|
-
@configuration.try(:[], :items_key) || :items
|
18
|
+
(@configuration.try(:[], :items_key) || :items).to_sym
|
19
19
|
end
|
20
20
|
|
21
21
|
def limit_key
|
22
|
-
@configuration.try(:[], :limit_key) || :limit
|
22
|
+
(@configuration.try(:[], :limit_key) || :limit).to_sym
|
23
23
|
end
|
24
24
|
|
25
25
|
def total_key
|
26
|
-
@configuration.try(:[], :total_key) || :total
|
26
|
+
(@configuration.try(:[], :total_key) || :total).to_sym
|
27
27
|
end
|
28
28
|
|
29
29
|
# Key used for determine current page
|
30
30
|
def pagination_key
|
31
|
-
@configuration.try(:[], :pagination_key) || :offset
|
31
|
+
(@configuration.try(:[], :pagination_key) || :offset).to_sym
|
32
32
|
end
|
33
33
|
|
34
34
|
# Strategy used for calculationg next pages and navigate pages
|
35
35
|
def pagination_strategy
|
36
|
-
@configuration.try(:[], :pagination_strategy) || :offset
|
36
|
+
(@configuration.try(:[], :pagination_strategy) || :offset).to_sym
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/lib/lhs/pagination.rb
CHANGED
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Record do
|
4
|
+
let(:offset) { 0 }
|
5
|
+
let(:data_hash) { { items: 98.times.map { { foo: 'bar' } }, total: 98, offset: offset, limit: 10 } }
|
6
|
+
|
7
|
+
let(:data) do
|
8
|
+
LHS::Data.new(data_hash, nil, Record)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:pagination) { OffsetPagination.new(data) }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
class Record < LHS::Record
|
15
|
+
endpoint ':datastore/v2/data'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'responds to pages_left' do
|
20
|
+
expect(pagination.pages_left).to eq(9)
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when there is no offset' do
|
24
|
+
let(:offset) { nil }
|
25
|
+
|
26
|
+
it 'responds to pages_left' do
|
27
|
+
# TODO i now set the nil offset to zero. Is this ok or wrong?
|
28
|
+
expect(pagination.pages_left).to eq(9)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Record do
|
4
|
+
let(:datastore) do
|
5
|
+
'http://datastore/v2'
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
LHC.config.placeholder('datastore', datastore)
|
10
|
+
class Record < LHS::Record
|
11
|
+
endpoint ':datastore/feedbacks'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'all' do
|
16
|
+
it 'is querying endpoint without pagination when using all' do
|
17
|
+
stub_request(:get, "#{datastore}/feedbacks?limit=100").to_return(status: 200, body: { items: 300.times.map { { foo: 'bar' } }, total: 300 }.to_json)
|
18
|
+
records = Record.all
|
19
|
+
expect(records).to be_kind_of Record
|
20
|
+
expect(records.size).to eq(300)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -96,7 +96,7 @@ describe LHS::Record do
|
|
96
96
|
expect(all.last).to eq 223
|
97
97
|
end
|
98
98
|
|
99
|
-
it 'also fetches all when there is
|
99
|
+
it 'also fetches all when there is no meta information for limit' do
|
100
100
|
stub_request(:get, "#{datastore}/feedbacks?limit=100")
|
101
101
|
.to_return(
|
102
102
|
status: 200,
|
@@ -151,7 +151,7 @@ describe LHS::Record do
|
|
151
151
|
expect(all.last).to eq 300
|
152
152
|
end
|
153
153
|
|
154
|
-
it 'also fetches all when there is
|
154
|
+
it 'also fetches all when there is no meta information for limit' do
|
155
155
|
stub_request(:get, "#{datastore}/feedbacks?limit=100")
|
156
156
|
.to_return(
|
157
157
|
status: 200,
|
@@ -229,7 +229,7 @@ describe LHS::Record do
|
|
229
229
|
expect(all.last).to eq 300
|
230
230
|
end
|
231
231
|
|
232
|
-
it 'also fetches all when there is
|
232
|
+
it 'also fetches all when there is no meta information for limit' do
|
233
233
|
stub_request(:get, "#{datastore}/feedbacks?limit=100")
|
234
234
|
.to_return(
|
235
235
|
status: 200,
|
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: 4.2.
|
4
|
+
version: 4.2.1
|
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: 2016-04-
|
11
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -273,8 +273,10 @@ files:
|
|
273
273
|
- spec/item/setter_spec.rb
|
274
274
|
- spec/item/update_spec.rb
|
275
275
|
- spec/item/validation_spec.rb
|
276
|
+
- spec/pagination/pages_left_spec.rb
|
276
277
|
- spec/proxy/load_spec.rb
|
277
278
|
- spec/rails_helper.rb
|
279
|
+
- spec/record/all_spec.rb
|
278
280
|
- spec/record/build_spec.rb
|
279
281
|
- spec/record/create_spec.rb
|
280
282
|
- spec/record/creation_failed_spec.rb
|
@@ -328,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
328
330
|
requirements:
|
329
331
|
- Ruby >= 1.9.2
|
330
332
|
rubyforge_project:
|
331
|
-
rubygems_version: 2.
|
333
|
+
rubygems_version: 2.4.8
|
332
334
|
signing_key:
|
333
335
|
specification_version: 4
|
334
336
|
summary: Rails gem providing an easy, active-record-like interface for http json services
|
@@ -398,8 +400,10 @@ test_files:
|
|
398
400
|
- spec/item/setter_spec.rb
|
399
401
|
- spec/item/update_spec.rb
|
400
402
|
- spec/item/validation_spec.rb
|
403
|
+
- spec/pagination/pages_left_spec.rb
|
401
404
|
- spec/proxy/load_spec.rb
|
402
405
|
- spec/rails_helper.rb
|
406
|
+
- spec/record/all_spec.rb
|
403
407
|
- spec/record/build_spec.rb
|
404
408
|
- spec/record/create_spec.rb
|
405
409
|
- spec/record/creation_failed_spec.rb
|