grape-kaminari 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +21 -0
- data/.rubocop.yml +7 -20
- data/Gemfile.lock +60 -47
- data/README.md +1 -1
- data/grape-kaminari.gemspec +3 -3
- data/lib/grape/kaminari/max_value_validator.rb +1 -1
- data/lib/grape/kaminari/version.rb +1 -1
- data/spec/{kaminari_spec.rb → grape/kaminari_spec.rb} +35 -36
- data/spec/spec_helper.rb +1 -1
- metadata +9 -11
- data/.travis.yml +0 -6
- data/spec/paginate_helper_spec.rb +0 -95
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5282850782bd08c0a0719eaad85f84b406f1a7419b9755162f939dc7f7aa71bc
|
4
|
+
data.tar.gz: 1fbe1503fe2149f82413c3e934452c85bfe190657077fbd1607e6a10beb812b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 644acde6f381781e2ef22c484c72fd9c754f7b72382e88fb3047bd71686c9284f65ba4154d887ba66ed45dc164fbb2d1902dfefbcb9310ea42124b5f9146e8cc
|
7
|
+
data.tar.gz: 12552dd5e9ce60c46726554e51cdffc01d1782b7a026f5298141f6c9b60e29ab0c05ce799eab01ae73acc14f458a08a6127b06d2357948ebc89b60681e5f3b71
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Test
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- main
|
6
|
+
pull_request:
|
7
|
+
branches:
|
8
|
+
- main
|
9
|
+
jobs:
|
10
|
+
ruby:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ["2.5", "2.6", "2.7", "3.0"]
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
bundler-cache: true
|
21
|
+
- run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -1,26 +1,13 @@
|
|
1
|
+
inherit_gem:
|
2
|
+
rubocop-bsm:
|
3
|
+
- default.yml
|
4
|
+
inherit_mode:
|
5
|
+
merge:
|
6
|
+
- Exclude
|
7
|
+
|
1
8
|
AllCops:
|
2
9
|
TargetRubyVersion: "2.5"
|
3
|
-
NewCops: enable
|
4
|
-
|
5
|
-
Metrics/AbcSize:
|
6
|
-
Enabled: false
|
7
|
-
Metrics/BlockLength:
|
8
|
-
Exclude:
|
9
|
-
- spec/**/*_spec.rb
|
10
|
-
Metrics/MethodLength:
|
11
|
-
Max: 20
|
12
10
|
|
13
11
|
Naming/FileName:
|
14
12
|
Exclude:
|
15
13
|
- lib/grape-kaminari.rb
|
16
|
-
|
17
|
-
Style/Documentation:
|
18
|
-
Enabled: false
|
19
|
-
Style/FrozenStringLiteralComment:
|
20
|
-
Enabled: false
|
21
|
-
Style/TrailingCommaInArguments:
|
22
|
-
EnforcedStyleForMultiline: consistent_comma
|
23
|
-
Style/TrailingCommaInArrayLiteral:
|
24
|
-
EnforcedStyleForMultiline: consistent_comma
|
25
|
-
Style/TrailingCommaInHashLiteral:
|
26
|
-
EnforcedStyleForMultiline: consistent_comma
|
data/Gemfile.lock
CHANGED
@@ -1,65 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grape-kaminari (0.4.
|
5
|
-
grape (>= 1.
|
4
|
+
grape-kaminari (0.4.2)
|
5
|
+
grape (>= 1.6.1, != 1.4.0)
|
6
6
|
kaminari-grape
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (6.
|
11
|
+
activesupport (6.1.3.1)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
-
i18n (>=
|
14
|
-
minitest (
|
15
|
-
tzinfo (~>
|
16
|
-
zeitwerk (~> 2.
|
17
|
-
ast (2.4.
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
zeitwerk (~> 2.3)
|
17
|
+
ast (2.4.2)
|
18
18
|
builder (3.2.4)
|
19
|
-
concurrent-ruby (1.1.
|
19
|
+
concurrent-ruby (1.1.8)
|
20
20
|
diff-lcs (1.4.4)
|
21
|
-
dry-configurable (0.
|
21
|
+
dry-configurable (0.12.1)
|
22
22
|
concurrent-ruby (~> 1.0)
|
23
|
-
dry-core (~> 0.
|
24
|
-
dry-equalizer (~> 0.2)
|
23
|
+
dry-core (~> 0.5, >= 0.5.0)
|
25
24
|
dry-container (0.7.2)
|
26
25
|
concurrent-ruby (~> 1.0)
|
27
26
|
dry-configurable (~> 0.1, >= 0.1.3)
|
28
|
-
dry-core (0.
|
27
|
+
dry-core (0.5.0)
|
29
28
|
concurrent-ruby (~> 1.0)
|
30
|
-
dry-equalizer (0.3.0)
|
31
29
|
dry-inflector (0.2.0)
|
32
|
-
dry-logic (1.0
|
30
|
+
dry-logic (1.2.0)
|
33
31
|
concurrent-ruby (~> 1.0)
|
34
|
-
dry-core (~> 0.
|
35
|
-
|
36
|
-
dry-types (1.4.0)
|
32
|
+
dry-core (~> 0.5, >= 0.5)
|
33
|
+
dry-types (1.5.1)
|
37
34
|
concurrent-ruby (~> 1.0)
|
38
35
|
dry-container (~> 0.3)
|
39
|
-
dry-core (~> 0.
|
40
|
-
dry-equalizer (~> 0.3)
|
36
|
+
dry-core (~> 0.5, >= 0.5)
|
41
37
|
dry-inflector (~> 0.1, >= 0.1.2)
|
42
38
|
dry-logic (~> 1.0, >= 1.0.2)
|
43
|
-
grape (1.
|
39
|
+
grape (1.6.2)
|
44
40
|
activesupport
|
45
41
|
builder
|
46
42
|
dry-types (>= 1.1)
|
47
43
|
mustermann-grape (~> 1.0.0)
|
48
44
|
rack (>= 1.3.0)
|
49
45
|
rack-accept
|
50
|
-
i18n (1.8.
|
46
|
+
i18n (1.8.10)
|
51
47
|
concurrent-ruby (~> 1.0)
|
52
48
|
kaminari-core (1.2.1)
|
53
49
|
kaminari-grape (1.0.1)
|
54
50
|
grape
|
55
51
|
kaminari-core (~> 1.0)
|
56
|
-
minitest (5.14.
|
52
|
+
minitest (5.14.4)
|
57
53
|
mustermann (1.1.1)
|
58
54
|
ruby2_keywords (~> 0.0.1)
|
59
55
|
mustermann-grape (1.0.1)
|
60
56
|
mustermann (>= 1.0.0)
|
61
|
-
parallel (1.20.
|
62
|
-
parser (
|
57
|
+
parallel (1.20.1)
|
58
|
+
parser (3.0.1.1)
|
63
59
|
ast (~> 2.4.1)
|
64
60
|
rack (2.2.3)
|
65
61
|
rack-accept (0.4.5)
|
@@ -67,40 +63,57 @@ GEM
|
|
67
63
|
rack-test (1.1.0)
|
68
64
|
rack (>= 1.0, < 3)
|
69
65
|
rainbow (3.0.0)
|
70
|
-
rake (13.0.
|
71
|
-
regexp_parser (1.
|
72
|
-
rexml (3.2.
|
66
|
+
rake (13.0.3)
|
67
|
+
regexp_parser (2.1.1)
|
68
|
+
rexml (3.2.5)
|
73
69
|
rspec (3.10.0)
|
74
70
|
rspec-core (~> 3.10.0)
|
75
71
|
rspec-expectations (~> 3.10.0)
|
76
72
|
rspec-mocks (~> 3.10.0)
|
77
|
-
rspec-core (3.10.
|
73
|
+
rspec-core (3.10.1)
|
78
74
|
rspec-support (~> 3.10.0)
|
79
|
-
rspec-expectations (3.10.
|
75
|
+
rspec-expectations (3.10.1)
|
80
76
|
diff-lcs (>= 1.2.0, < 2.0)
|
81
77
|
rspec-support (~> 3.10.0)
|
82
|
-
rspec-mocks (3.10.
|
78
|
+
rspec-mocks (3.10.2)
|
83
79
|
diff-lcs (>= 1.2.0, < 2.0)
|
84
80
|
rspec-support (~> 3.10.0)
|
85
|
-
rspec-support (3.10.
|
86
|
-
rubocop (1.
|
81
|
+
rspec-support (3.10.2)
|
82
|
+
rubocop (1.13.0)
|
87
83
|
parallel (~> 1.10)
|
88
|
-
parser (>=
|
84
|
+
parser (>= 3.0.0.0)
|
89
85
|
rainbow (>= 2.2.2, < 4.0)
|
90
|
-
regexp_parser (>= 1.8)
|
86
|
+
regexp_parser (>= 1.8, < 3.0)
|
91
87
|
rexml
|
92
|
-
rubocop-ast (>= 1.0.
|
88
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
93
89
|
ruby-progressbar (~> 1.7)
|
94
|
-
unicode-display_width (>= 1.4.0, <
|
95
|
-
rubocop-ast (1.
|
96
|
-
parser (>=
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
90
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
91
|
+
rubocop-ast (1.5.0)
|
92
|
+
parser (>= 3.0.1.1)
|
93
|
+
rubocop-bsm (0.5.9)
|
94
|
+
rubocop (~> 1.0)
|
95
|
+
rubocop-performance
|
96
|
+
rubocop-rails
|
97
|
+
rubocop-rake
|
98
|
+
rubocop-rspec
|
99
|
+
rubocop-performance (1.11.1)
|
100
|
+
rubocop (>= 1.7.0, < 2.0)
|
101
|
+
rubocop-ast (>= 0.4.0)
|
102
|
+
rubocop-rails (2.9.1)
|
103
|
+
activesupport (>= 4.2.0)
|
104
|
+
rack (>= 1.1)
|
105
|
+
rubocop (>= 0.90.0, < 2.0)
|
106
|
+
rubocop-rake (0.5.1)
|
107
|
+
rubocop
|
108
|
+
rubocop-rspec (2.3.0)
|
109
|
+
rubocop (~> 1.0)
|
110
|
+
rubocop-ast (>= 1.1.0)
|
111
|
+
ruby-progressbar (1.11.0)
|
112
|
+
ruby2_keywords (0.0.4)
|
113
|
+
tzinfo (2.0.4)
|
114
|
+
concurrent-ruby (~> 1.0)
|
115
|
+
unicode-display_width (2.0.0)
|
116
|
+
zeitwerk (2.4.2)
|
104
117
|
|
105
118
|
PLATFORMS
|
106
119
|
ruby
|
@@ -111,7 +124,7 @@ DEPENDENCIES
|
|
111
124
|
rack-test
|
112
125
|
rake
|
113
126
|
rspec
|
114
|
-
rubocop
|
127
|
+
rubocop-bsm
|
115
128
|
|
116
129
|
BUNDLED WITH
|
117
130
|
2.1.4
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Grape::Kaminari
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Test](https://github.com/bsm/grape-kaminari/actions/workflows/test.yml/badge.svg)](https://github.com/bsm/grape-kaminari/actions/workflows/test.yml)
|
4
4
|
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
|
5
5
|
|
6
6
|
[kaminari](https://github.com/kaminari/kaminari) paginator integration for [grape](https://github.com/intridea/grape) API framework.
|
data/grape-kaminari.gemspec
CHANGED
@@ -12,17 +12,17 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.homepage = ''
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
|
-
spec.files = `git ls-files -z`.split("\x0").reject {
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject {|f| f.start_with?('spec/') }
|
16
16
|
spec.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
spec.required_ruby_version = '>= 2.5'
|
19
19
|
|
20
|
-
spec.add_runtime_dependency 'grape', '>= 1.
|
20
|
+
spec.add_runtime_dependency 'grape', '>= 1.6.1', '!= 1.4.0'
|
21
21
|
spec.add_runtime_dependency 'kaminari-grape'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler'
|
24
24
|
spec.add_development_dependency 'rack-test'
|
25
25
|
spec.add_development_dependency 'rake'
|
26
26
|
spec.add_development_dependency 'rspec'
|
27
|
-
spec.add_development_dependency 'rubocop'
|
27
|
+
spec.add_development_dependency 'rubocop-bsm'
|
28
28
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Grape
|
2
2
|
module Kaminari
|
3
|
-
class MaxValueValidator < Grape::Validations::Base
|
3
|
+
class MaxValueValidator < Grape::Validations::Validators::Base
|
4
4
|
def validate_param!(attr_name, params)
|
5
5
|
attr = params[attr_name]
|
6
6
|
return unless attr.is_a?(Integer) && @option && attr > @option
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class PaginatedAPI < Grape::API
|
4
|
-
include Grape::Kaminari
|
5
|
-
end
|
6
|
-
|
7
3
|
describe Grape::Kaminari do
|
8
|
-
subject
|
4
|
+
subject do
|
5
|
+
Class.new(Grape::API) do
|
6
|
+
include Grape::Kaminari
|
7
|
+
end
|
8
|
+
end
|
9
9
|
|
10
10
|
def declared_params
|
11
11
|
subject.namespace_stackable(:declared_params).flatten
|
@@ -21,12 +21,12 @@ describe Grape::Kaminari do
|
|
21
21
|
expect(declared_params).to eq(%i[page per_page])
|
22
22
|
end
|
23
23
|
|
24
|
-
it '
|
24
|
+
it 'supports legacy declarations' do
|
25
25
|
subject.paginate
|
26
26
|
expect(declared_params).to eq(%i[page per_page offset])
|
27
27
|
end
|
28
28
|
|
29
|
-
it '
|
29
|
+
it 'does not stumble across repeated declarations' do
|
30
30
|
subject.paginate offset: false
|
31
31
|
subject.params do
|
32
32
|
optional :extra
|
@@ -90,42 +90,41 @@ describe Grape::Kaminari do
|
|
90
90
|
expect(params['offset'][:default]).to eq(0)
|
91
91
|
end
|
92
92
|
end
|
93
|
-
end
|
94
93
|
|
95
|
-
describe 'custom paginated api' do
|
96
|
-
|
97
|
-
|
98
|
-
let(:params) { subject.routes.first.params }
|
94
|
+
describe 'custom paginated api' do
|
95
|
+
let(:app) { subject }
|
96
|
+
let(:params) { subject.routes.first.params }
|
99
97
|
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
before do
|
99
|
+
subject.params do
|
100
|
+
use :pagination, per_page: 99, max_per_page: 999, offset: 9
|
101
|
+
end
|
102
|
+
subject.get('/') { 'OK' }
|
103
103
|
end
|
104
|
-
subject.get('/') { 'OK' }
|
105
|
-
end
|
106
104
|
|
107
|
-
|
108
|
-
|
109
|
-
|
105
|
+
it 'defaults :per_page to customized value' do
|
106
|
+
expect(params['per_page'][:default]).to eq(99)
|
107
|
+
end
|
110
108
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
109
|
+
it 'succeeds when :per_page is within :max_value' do
|
110
|
+
get('/', page: 1, per_page: 999)
|
111
|
+
expect(last_response.status).to eq(200)
|
112
|
+
end
|
115
113
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
114
|
+
it 'ensures :per_page is within :max_value' do
|
115
|
+
get('/', page: 1, per_page: 1_000)
|
116
|
+
expect(last_response.status).to eq(400)
|
117
|
+
expect(last_response.body).to match(/per_page must be less than or equal 999/)
|
118
|
+
end
|
121
119
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
it 'ensures :per_page is numeric' do
|
121
|
+
get('/', page: 1, per_page: 'foo')
|
122
|
+
expect(last_response.status).to eq(400)
|
123
|
+
expect(last_response.body).to match(/per_page is invalid/)
|
124
|
+
end
|
127
125
|
|
128
|
-
|
129
|
-
|
126
|
+
it 'defaults :offset to customized value' do
|
127
|
+
expect(params['offset'][:default]).to eq(9)
|
128
|
+
end
|
130
129
|
end
|
131
130
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rack/test'
|
|
4
4
|
|
5
5
|
# Requires supporting files with custom matchers and macros, etc,
|
6
6
|
# in ./support/ and its subdirectories.
|
7
|
-
Dir[File.expand_path('./support/**/*.rb', __dir__)].sort.each {
|
7
|
+
Dir[File.expand_path('./support/**/*.rb', __dir__)].sort.each {|f| require f }
|
8
8
|
|
9
9
|
I18n.enforce_available_locales = false
|
10
10
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-kaminari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tymon Tobolski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grape
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 1.6.1
|
21
21
|
- - "!="
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.4.0
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version:
|
30
|
+
version: 1.6.1
|
31
31
|
- - "!="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.4.0
|
@@ -102,7 +102,7 @@ dependencies:
|
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
|
-
name: rubocop
|
105
|
+
name: rubocop-bsm
|
106
106
|
requirement: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
@@ -122,9 +122,9 @@ executables: []
|
|
122
122
|
extensions: []
|
123
123
|
extra_rdoc_files: []
|
124
124
|
files:
|
125
|
+
- ".github/workflows/test.yml"
|
125
126
|
- ".gitignore"
|
126
127
|
- ".rubocop.yml"
|
127
|
-
- ".travis.yml"
|
128
128
|
- CHANGELOG.md
|
129
129
|
- Gemfile
|
130
130
|
- Gemfile.lock
|
@@ -136,8 +136,7 @@ files:
|
|
136
136
|
- lib/grape/kaminari.rb
|
137
137
|
- lib/grape/kaminari/max_value_validator.rb
|
138
138
|
- lib/grape/kaminari/version.rb
|
139
|
-
- spec/kaminari_spec.rb
|
140
|
-
- spec/paginate_helper_spec.rb
|
139
|
+
- spec/grape/kaminari_spec.rb
|
141
140
|
- spec/spec_helper.rb
|
142
141
|
homepage: ''
|
143
142
|
licenses:
|
@@ -158,11 +157,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
157
|
- !ruby/object:Gem::Version
|
159
158
|
version: '0'
|
160
159
|
requirements: []
|
161
|
-
rubygems_version: 3.
|
160
|
+
rubygems_version: 3.2.15
|
162
161
|
signing_key:
|
163
162
|
specification_version: 4
|
164
163
|
summary: kaminari integration for grape
|
165
164
|
test_files:
|
166
|
-
- spec/kaminari_spec.rb
|
167
|
-
- spec/paginate_helper_spec.rb
|
165
|
+
- spec/grape/kaminari_spec.rb
|
168
166
|
- spec/spec_helper.rb
|
data/.travis.yml
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
class PaginatedAPI < Grape::API
|
5
|
-
include Grape::Kaminari
|
6
|
-
|
7
|
-
params do
|
8
|
-
use :pagination
|
9
|
-
end
|
10
|
-
get '' do
|
11
|
-
paginate(Kaminari.paginate_array((1..10).to_a))
|
12
|
-
end
|
13
|
-
|
14
|
-
params do
|
15
|
-
use :pagination, offset: false
|
16
|
-
end
|
17
|
-
get 'no-offset' do
|
18
|
-
paginate(Kaminari.paginate_array((1..10).to_a))
|
19
|
-
end
|
20
|
-
|
21
|
-
params do
|
22
|
-
use :pagination, offset: false
|
23
|
-
end
|
24
|
-
get 'no-count' do
|
25
|
-
paginate(Kaminari.paginate_array((1..10).to_a), without_count: true)
|
26
|
-
end
|
27
|
-
|
28
|
-
resource :sub do
|
29
|
-
params do
|
30
|
-
use :pagination, per_page: 2
|
31
|
-
end
|
32
|
-
get '/' do
|
33
|
-
paginate(Kaminari.paginate_array((1..10).to_a))
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe Grape::Kaminari do
|
39
|
-
subject { PaginatedAPI.new }
|
40
|
-
let(:app) { subject }
|
41
|
-
let(:json) { JSON.parse(last_response.body) }
|
42
|
-
let(:header) { last_response.header }
|
43
|
-
|
44
|
-
describe 'paginated helper' do
|
45
|
-
it 'returns the first page' do
|
46
|
-
get '/', page: 1, per_page: 3
|
47
|
-
expect(json).to eq [1, 2, 3]
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'returns the second page' do
|
51
|
-
get '/', page: 2, per_page: 3
|
52
|
-
expect(json).to eq [4, 5, 6]
|
53
|
-
end
|
54
|
-
|
55
|
-
# This is here to ensure that Kaminari can handle `padding(false)`
|
56
|
-
# and still do the right thing.
|
57
|
-
it 'works when offset is false' do
|
58
|
-
get '/no-offset', page: 1, per_page: 3
|
59
|
-
expect(json).to eq [1, 2, 3]
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'works without count' do
|
63
|
-
get '/no-count', page: 2, per_page: 3
|
64
|
-
expect(json).to eq [4, 5, 6]
|
65
|
-
expect(header).to include(
|
66
|
-
'X-Per-Page' => '3',
|
67
|
-
'X-Page' => '2',
|
68
|
-
'X-Next-Page' => '3',
|
69
|
-
'X-Prev-Page' => '1',
|
70
|
-
)
|
71
|
-
expect(header).not_to include(
|
72
|
-
'X-Total',
|
73
|
-
'X-Total-Pages',
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'sets headers' do
|
78
|
-
get '/', page: 3, per_page: 2, offset: 1
|
79
|
-
expect(header).to include(
|
80
|
-
'X-Total' => '10',
|
81
|
-
'X-Total-Pages' => '5',
|
82
|
-
'X-Per-Page' => '2',
|
83
|
-
'X-Page' => '3',
|
84
|
-
'X-Next-Page' => '4',
|
85
|
-
'X-Prev-Page' => '2',
|
86
|
-
'X-Offset' => '1',
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'can be inherited' do
|
91
|
-
get '/sub', page: 1
|
92
|
-
expect(json).to eq [1, 2]
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|