api-pagination 4.5.2 → 4.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/lib/api-pagination.rb +2 -2
- data/lib/api-pagination/version.rb +2 -2
- data/spec/api-pagination_spec.rb +56 -20
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d77fb4d992aae484c741d89235cf7cbdb998c3f
|
4
|
+
data.tar.gz: e267de21b868427e1788392d7ceffd30cbee68f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e68ca7f44c0729540fd32a98b5106c803c2cdd96a73fa77c52dfa179f5ed00f7f529259838ebc28d10172efe2f421d66feb303f99c3e5eeaf73e7db9acd2b87
|
7
|
+
data.tar.gz: 3bec93cd7ff6bb0d33de4720317e6a459787758b4c7d952f4edd7757eb309769b207c829070f38ccad2643121bd8af052b89a92b9e985d92da2f4b15d79cde9a
|
data/lib/api-pagination.rb
CHANGED
@@ -25,7 +25,7 @@ module ApiPagination
|
|
25
25
|
pages[:prev] = collection.current_page - 1
|
26
26
|
end
|
27
27
|
|
28
|
-
unless collection.last_page?
|
28
|
+
unless collection.last_page? || (ApiPagination.config.paginator == :kaminari && collection.out_of_range?)
|
29
29
|
pages[:last] = collection.total_pages
|
30
30
|
pages[:next] = collection.current_page + 1
|
31
31
|
end
|
@@ -60,7 +60,7 @@ module ApiPagination
|
|
60
60
|
if defined?(Sequel::Dataset) && collection.kind_of?(Sequel::Dataset)
|
61
61
|
collection.paginate(options[:page], options[:per_page])
|
62
62
|
else
|
63
|
-
collection.paginate(
|
63
|
+
collection.paginate(options)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
data/spec/api-pagination_spec.rb
CHANGED
@@ -1,30 +1,66 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ApiPagination do
|
4
|
-
let(:collection) {
|
5
|
-
let(:paginate_array_options) {
|
4
|
+
let(:collection) {(1..100).to_a}
|
5
|
+
let(:paginate_array_options) {{ total_count: 1000 }}
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
describe "#paginate" do
|
8
|
+
context 'Using kaminari' do
|
9
|
+
before do
|
10
|
+
ApiPagination.config.paginator = :kaminari
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
ApiPagination.config.paginator = ENV['PAGINATOR'].to_sym
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should accept paginate_array_options option' do
|
18
|
+
expect(Kaminari).to receive(:paginate_array)
|
19
|
+
.with(collection, paginate_array_options)
|
20
|
+
.and_call_original
|
21
|
+
|
22
|
+
ApiPagination.paginate(
|
23
|
+
collection,
|
24
|
+
{
|
25
|
+
per_page: 30,
|
26
|
+
paginate_array_options: paginate_array_options
|
27
|
+
}
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.pages_from' do
|
32
|
+
subject {described_class.pages_from collection}
|
11
33
|
|
12
|
-
|
13
|
-
|
34
|
+
context 'on empty collection' do
|
35
|
+
let(:collection) {ApiPagination.paginate [], page: 1}
|
36
|
+
|
37
|
+
it {is_expected.to be_empty}
|
38
|
+
end
|
39
|
+
end
|
14
40
|
end
|
15
41
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
42
|
+
context 'Using will_paginate' do
|
43
|
+
before do
|
44
|
+
ApiPagination.config.paginator = :will_paginate
|
45
|
+
end
|
46
|
+
|
47
|
+
after do
|
48
|
+
ApiPagination.config.paginator = ENV['PAGINATOR'].to_sym
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'passing in total_entries in options' do
|
52
|
+
it 'should set total_entries using the passed in value' do
|
53
|
+
paginated_collection = ApiPagination.paginate(collection, total_entries: 3000)
|
54
|
+
expect(paginated_collection.total_entries).to eq(3000)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'passing in collection only' do
|
59
|
+
it 'should set total_entries using the size of the collection ' do
|
60
|
+
paginated_collection = ApiPagination.paginate(collection)
|
61
|
+
expect(paginated_collection.total_entries).to eq(100)
|
62
|
+
end
|
63
|
+
end
|
28
64
|
end
|
29
65
|
end
|
30
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.6.8
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Link header pagination for Rails and Grape APIs. Don't use the request body.
|