api-pagination 4.5.2 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fb30057d988236c8f5c6e557f7feea70fd79bd5
4
- data.tar.gz: 98a0b719a0a1ae299bde47edd30b8a6e2ed015e2
3
+ metadata.gz: 5d77fb4d992aae484c741d89235cf7cbdb998c3f
4
+ data.tar.gz: e267de21b868427e1788392d7ceffd30cbee68f7
5
5
  SHA512:
6
- metadata.gz: 9b8a65195ac6a5feb65932e020ffa460508f8b53e47b16c34a7c22fd2e3816ffaa7d894590bc14593e3d90991adad14bdd9698a0ac36078588ccea6a35479736
7
- data.tar.gz: d29a8fa3d95a922f4be7a880a18f425a32a391e40ae8ebbef46f6c149fcd561153e01bda567e1e5c65edbffd3bf04422e2d68ef6f671efcad2e98e19209c04e8
6
+ metadata.gz: 4e68ca7f44c0729540fd32a98b5106c803c2cdd96a73fa77c52dfa179f5ed00f7f529259838ebc28d10172efe2f421d66feb303f99c3e5eeaf73e7db9acd2b87
7
+ data.tar.gz: 3bec93cd7ff6bb0d33de4720317e6a459787758b4c7d952f4edd7757eb309769b207c829070f38ccad2643121bd8af052b89a92b9e985d92da2f4b15d79cde9a
@@ -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(:page => options[:page], :per_page => options[:per_page])
63
+ collection.paginate(options)
64
64
  end
65
65
  end
66
66
 
@@ -1,8 +1,8 @@
1
1
  module ApiPagination
2
2
  class Version
3
3
  MAJOR = 4
4
- MINOR = 5
5
- PATCH = 2
4
+ MINOR = 6
5
+ PATCH = 0
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].join('.')
@@ -1,30 +1,66 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ApiPagination do
4
- let(:collection) { (1..100).to_a }
5
- let(:paginate_array_options) { { total_count: 1000 } }
4
+ let(:collection) {(1..100).to_a}
5
+ let(:paginate_array_options) {{ total_count: 1000 }}
6
6
 
7
- context 'Using kaminari' do
8
- before do
9
- ApiPagination.config.paginator = :kaminari
10
- end
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
- after do
13
- ApiPagination.config.paginator = ENV['PAGINATOR'].to_sym
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
- it 'should accept paginate_array_options option' do
17
- expect(Kaminari).to receive(:paginate_array)
18
- .with(collection, paginate_array_options)
19
- .and_call_original
20
-
21
- ApiPagination.paginate(
22
- collection,
23
- {
24
- per_page: 30,
25
- paginate_array_options: paginate_array_options
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.5.2
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: 2016-12-29 00:00:00.000000000 Z
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.5.1
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.