lhs 2.1.1 → 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0136ac0223418ddf3f141de5fb9a469a7fe24374
4
- data.tar.gz: 448e6a48140f37728dfe40083edb15638649de74
3
+ metadata.gz: 6718201cc8059a9b8600853712600a7913a05f98
4
+ data.tar.gz: f1884ac3f14c9617d81699ae18c754647644e105
5
5
  SHA512:
6
- metadata.gz: b4833493e3121a9177210180f96b1b5df0b496b9c8f6945c7e73c00ea8117bb6dd65cb3bc63fef3f60e1a357b3ccfcf1d958c86177e67d5490f705edbcbfd65e
7
- data.tar.gz: 5724f5743af929cc146863a897161d2625748ef6fff40ae36e8b48446c8772d7c88138ebae10ca256862504c047d6129a7afcb31f9334d4b477edc9438dc8875
6
+ metadata.gz: f434ad9a119d2e332fb3915a07c60b677fa035030d1c3f9483a4eef99cd72c36c85c1d32ae02d9250cd5a591b7605835001c02ba905f67986afb67b35f5830d0
7
+ data.tar.gz: 5de257a8abdf67f3598b516a7fdfe0ce93b53d8f440dbb161a47b6769b62c62dd270c99a56f925bf61bea689cdde33bde91527e09b97704a3fd6b16cf6271092
@@ -37,6 +37,33 @@ class LHS::Data
37
37
  def _raw=(raw)
38
38
  raw.to_hash.deep_symbolize_keys! if raw && raw.respond_to?(:to_hash)
39
39
  @_raw = raw
40
+
41
+ def current_page
42
+ offset + 1
43
+ end
44
+
45
+ def first_page
46
+ 1
47
+ end
48
+
49
+ def last_page
50
+ total_pages
51
+ end
52
+
53
+ def prev_page
54
+ current_page - 1
55
+ end
56
+
57
+ def next_page
58
+ current_page + 1
59
+ end
60
+
61
+ def limit_value
62
+ limit
63
+ end
64
+
65
+ def total_pages
66
+ total / limit
40
67
  end
41
68
 
42
69
  protected
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "2.1.1"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -0,0 +1,60 @@
1
+ require 'rails_helper'
2
+
3
+ describe LHS::Data do
4
+ context 'pagination' do
5
+ let(:datastore) { 'http://local.ch/v2' }
6
+ let(:record) { Feedback.where(entry_id: 1) }
7
+ let(:total) { 200 }
8
+ let(:total_pages) { total / limit }
9
+ let(:current_page) { offset + 1 }
10
+ let(:prev_page) { current_page - 1 }
11
+ let(:next_page) { current_page + 1 }
12
+ let(:offset) { 0 }
13
+ let(:limit) { 10 }
14
+ let(:body_json) do
15
+ {
16
+ items: [],
17
+ total: total,
18
+ offset: offset,
19
+ limit: limit
20
+ }.to_json
21
+ end
22
+
23
+ before(:each) do
24
+ LHC.config.placeholder('datastore', datastore)
25
+ class Feedback < LHS::Service
26
+ endpoint ':datastore/feedbacks'
27
+ end
28
+ stub_request(:get, 'http://local.ch/v2/feedbacks?entry_id=1')
29
+ .to_return(body: body_json)
30
+ end
31
+
32
+ it 'responds to limit_value' do
33
+ expect(record.limit_value).to eq(limit)
34
+ end
35
+
36
+ it 'responds to total_pages' do
37
+ expect(record.total_pages).to eq(total_pages)
38
+ end
39
+
40
+ it 'responds to current_page' do
41
+ expect(record.current_page).to eq(current_page)
42
+ end
43
+
44
+ it 'responds to first_page' do
45
+ expect(record.first_page).to eq(1)
46
+ end
47
+
48
+ it 'responds to last_page' do
49
+ expect(record.last_page).to eq(total_pages)
50
+ end
51
+
52
+ it 'responds to prev_page' do
53
+ expect(record.prev_page).to eq(prev_page)
54
+ end
55
+
56
+ it 'responds to next_page' do
57
+ expect(record.next_page).to eq(next_page)
58
+ end
59
+ end
60
+ end
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: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - local.ch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -168,6 +168,7 @@ files:
168
168
  - spec/data/collection_spec.rb
169
169
  - spec/data/item_spec.rb
170
170
  - spec/data/merge_spec.rb
171
+ - spec/data/pagination_spec.rb
171
172
  - spec/data/raw_spec.rb
172
173
  - spec/data/respond_to_spec.rb
173
174
  - spec/data/root_spec.rb
@@ -284,6 +285,7 @@ test_files:
284
285
  - spec/data/collection_spec.rb
285
286
  - spec/data/item_spec.rb
286
287
  - spec/data/merge_spec.rb
288
+ - spec/data/pagination_spec.rb
287
289
  - spec/data/raw_spec.rb
288
290
  - spec/data/respond_to_spec.rb
289
291
  - spec/data/root_spec.rb