grape-kaminari 0.4.3 → 0.4.4
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/.github/workflows/test.yml +1 -1
- data/Gemfile +5 -0
- data/Gemfile.lock +57 -55
- data/grape-kaminari.gemspec +0 -5
- data/lib/grape/kaminari/version.rb +1 -1
- metadata +4 -66
- data/spec/grape/kaminari_params_spec.rb +0 -94
- data/spec/grape/kaminari_spec.rb +0 -130
- data/spec/spec_helper.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e7bef8d7546d576aca8f4b0f1bdb1e633c4ea4d63b011063228874e226b0826f
|
|
4
|
+
data.tar.gz: 0ca3f5acfad14c2a5bddea2e4605ebeedce883f22f41d93cd900dac8d6113a84
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b12a1b1e568af31df333ff20f617d9e0687b0177430fd8a8be40f92b7b44fc6fa7777278f0629302e0f939b7901c66e5df8a3cce19702131c1d800edea491b8
|
|
7
|
+
data.tar.gz: 90ac0dad49e5910652100d3518ac38fab54f8903004a4ceef027fa58d3f1bc25b27988735dfde36ba7af0658b364f858b40c4c7b3bd22e724b0651ddd7129b15
|
data/.github/workflows/test.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,111 +1,113 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
grape-kaminari (0.4.
|
|
4
|
+
grape-kaminari (0.4.4)
|
|
5
5
|
grape (>= 1.6.1)
|
|
6
6
|
kaminari-grape
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
activesupport (7.0.
|
|
11
|
+
activesupport (7.0.4.2)
|
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
13
13
|
i18n (>= 1.6, < 2)
|
|
14
14
|
minitest (>= 5.1)
|
|
15
15
|
tzinfo (~> 2.0)
|
|
16
16
|
ast (2.4.2)
|
|
17
17
|
builder (3.2.4)
|
|
18
|
-
concurrent-ruby (1.
|
|
18
|
+
concurrent-ruby (1.2.0)
|
|
19
19
|
diff-lcs (1.5.0)
|
|
20
|
-
dry-
|
|
20
|
+
dry-core (1.0.0)
|
|
21
21
|
concurrent-ruby (~> 1.0)
|
|
22
|
-
|
|
23
|
-
dry-
|
|
22
|
+
zeitwerk (~> 2.6)
|
|
23
|
+
dry-inflector (1.0.0)
|
|
24
|
+
dry-logic (1.5.0)
|
|
24
25
|
concurrent-ruby (~> 1.0)
|
|
25
|
-
dry-
|
|
26
|
-
|
|
26
|
+
dry-core (~> 1.0, < 2)
|
|
27
|
+
zeitwerk (~> 2.6)
|
|
28
|
+
dry-types (1.7.0)
|
|
27
29
|
concurrent-ruby (~> 1.0)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
concurrent-ruby (~> 1.0)
|
|
34
|
-
dry-container (~> 0.3)
|
|
35
|
-
dry-core (~> 0.5, >= 0.5)
|
|
36
|
-
dry-inflector (~> 0.1, >= 0.1.2)
|
|
37
|
-
dry-logic (~> 1.0, >= 1.0.2)
|
|
38
|
-
grape (1.6.2)
|
|
30
|
+
dry-core (~> 1.0, < 2)
|
|
31
|
+
dry-inflector (~> 1.0, < 2)
|
|
32
|
+
dry-logic (>= 1.4, < 2)
|
|
33
|
+
zeitwerk (~> 2.6)
|
|
34
|
+
grape (1.7.0)
|
|
39
35
|
activesupport
|
|
40
36
|
builder
|
|
41
37
|
dry-types (>= 1.1)
|
|
42
38
|
mustermann-grape (~> 1.0.0)
|
|
43
39
|
rack (>= 1.3.0)
|
|
44
40
|
rack-accept
|
|
45
|
-
i18n (1.
|
|
41
|
+
i18n (1.12.0)
|
|
46
42
|
concurrent-ruby (~> 1.0)
|
|
43
|
+
json (2.6.3)
|
|
47
44
|
kaminari-core (1.2.2)
|
|
48
45
|
kaminari-grape (1.0.1)
|
|
49
46
|
grape
|
|
50
47
|
kaminari-core (~> 1.0)
|
|
51
|
-
minitest (5.
|
|
52
|
-
mustermann (
|
|
48
|
+
minitest (5.17.0)
|
|
49
|
+
mustermann (3.0.0)
|
|
53
50
|
ruby2_keywords (~> 0.0.1)
|
|
54
|
-
mustermann-grape (1.0.
|
|
51
|
+
mustermann-grape (1.0.2)
|
|
55
52
|
mustermann (>= 1.0.0)
|
|
56
|
-
parallel (1.
|
|
57
|
-
parser (3.
|
|
53
|
+
parallel (1.22.1)
|
|
54
|
+
parser (3.2.0.0)
|
|
58
55
|
ast (~> 2.4.1)
|
|
59
|
-
rack (
|
|
56
|
+
rack (3.0.4.1)
|
|
60
57
|
rack-accept (0.4.5)
|
|
61
58
|
rack (>= 0.4)
|
|
62
|
-
rack-test (
|
|
63
|
-
rack (>= 1.
|
|
64
|
-
rainbow (3.
|
|
59
|
+
rack-test (2.0.2)
|
|
60
|
+
rack (>= 1.3)
|
|
61
|
+
rainbow (3.1.1)
|
|
65
62
|
rake (13.0.6)
|
|
66
|
-
regexp_parser (2.2
|
|
63
|
+
regexp_parser (2.6.2)
|
|
67
64
|
rexml (3.2.5)
|
|
68
|
-
rspec (3.
|
|
69
|
-
rspec-core (~> 3.
|
|
70
|
-
rspec-expectations (~> 3.
|
|
71
|
-
rspec-mocks (~> 3.
|
|
72
|
-
rspec-core (3.
|
|
73
|
-
rspec-support (~> 3.
|
|
74
|
-
rspec-expectations (3.
|
|
65
|
+
rspec (3.12.0)
|
|
66
|
+
rspec-core (~> 3.12.0)
|
|
67
|
+
rspec-expectations (~> 3.12.0)
|
|
68
|
+
rspec-mocks (~> 3.12.0)
|
|
69
|
+
rspec-core (3.12.0)
|
|
70
|
+
rspec-support (~> 3.12.0)
|
|
71
|
+
rspec-expectations (3.12.2)
|
|
75
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
76
|
-
rspec-support (~> 3.
|
|
77
|
-
rspec-mocks (3.
|
|
73
|
+
rspec-support (~> 3.12.0)
|
|
74
|
+
rspec-mocks (3.12.3)
|
|
78
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
79
|
-
rspec-support (~> 3.
|
|
80
|
-
rspec-support (3.
|
|
81
|
-
rubocop (1.
|
|
76
|
+
rspec-support (~> 3.12.0)
|
|
77
|
+
rspec-support (3.12.0)
|
|
78
|
+
rubocop (1.44.1)
|
|
79
|
+
json (~> 2.3)
|
|
82
80
|
parallel (~> 1.10)
|
|
83
|
-
parser (>= 3.
|
|
81
|
+
parser (>= 3.2.0.0)
|
|
84
82
|
rainbow (>= 2.2.2, < 4.0)
|
|
85
83
|
regexp_parser (>= 1.8, < 3.0)
|
|
86
|
-
rexml
|
|
87
|
-
rubocop-ast (>= 1.
|
|
84
|
+
rexml (>= 3.2.5, < 4.0)
|
|
85
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
|
88
86
|
ruby-progressbar (~> 1.7)
|
|
89
|
-
unicode-display_width (>=
|
|
90
|
-
rubocop-ast (1.
|
|
91
|
-
parser (>= 3.
|
|
92
|
-
rubocop-bsm (0.6.
|
|
87
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
88
|
+
rubocop-ast (1.24.1)
|
|
89
|
+
parser (>= 3.1.1.0)
|
|
90
|
+
rubocop-bsm (0.6.1)
|
|
93
91
|
rubocop (~> 1.0)
|
|
94
92
|
rubocop-performance
|
|
95
93
|
rubocop-rake
|
|
96
94
|
rubocop-rspec
|
|
97
|
-
rubocop-
|
|
95
|
+
rubocop-capybara (2.17.0)
|
|
96
|
+
rubocop (~> 1.41)
|
|
97
|
+
rubocop-performance (1.15.2)
|
|
98
98
|
rubocop (>= 1.7.0, < 2.0)
|
|
99
99
|
rubocop-ast (>= 0.4.0)
|
|
100
100
|
rubocop-rake (0.6.0)
|
|
101
101
|
rubocop (~> 1.0)
|
|
102
|
-
rubocop-rspec (2.
|
|
103
|
-
rubocop (~> 1.
|
|
102
|
+
rubocop-rspec (2.18.1)
|
|
103
|
+
rubocop (~> 1.33)
|
|
104
|
+
rubocop-capybara (~> 2.17)
|
|
104
105
|
ruby-progressbar (1.11.0)
|
|
105
106
|
ruby2_keywords (0.0.5)
|
|
106
|
-
tzinfo (2.0.
|
|
107
|
+
tzinfo (2.0.6)
|
|
107
108
|
concurrent-ruby (~> 1.0)
|
|
108
|
-
unicode-display_width (2.
|
|
109
|
+
unicode-display_width (2.4.2)
|
|
110
|
+
zeitwerk (2.6.6)
|
|
109
111
|
|
|
110
112
|
PLATFORMS
|
|
111
113
|
ruby
|
|
@@ -119,4 +121,4 @@ DEPENDENCIES
|
|
|
119
121
|
rubocop-bsm
|
|
120
122
|
|
|
121
123
|
BUNDLED WITH
|
|
122
|
-
2.
|
|
124
|
+
2.3.9
|
data/grape-kaminari.gemspec
CHANGED
|
@@ -13,7 +13,6 @@ Gem::Specification.new do |spec|
|
|
|
13
13
|
spec.license = 'MIT'
|
|
14
14
|
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject {|f| f.start_with?('spec/') }
|
|
16
|
-
spec.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
|
17
16
|
spec.require_paths = ['lib']
|
|
18
17
|
spec.required_ruby_version = '>= 2.7'
|
|
19
18
|
|
|
@@ -21,9 +20,5 @@ Gem::Specification.new do |spec|
|
|
|
21
20
|
spec.add_runtime_dependency 'kaminari-grape'
|
|
22
21
|
|
|
23
22
|
spec.add_development_dependency 'bundler'
|
|
24
|
-
spec.add_development_dependency 'rack-test'
|
|
25
|
-
spec.add_development_dependency 'rake'
|
|
26
|
-
spec.add_development_dependency 'rspec'
|
|
27
|
-
spec.add_development_dependency 'rubocop-bsm'
|
|
28
23
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
29
24
|
end
|
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.4
|
|
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: 2023-01-31 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: grape
|
|
@@ -53,62 +53,6 @@ dependencies:
|
|
|
53
53
|
- - ">="
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
55
|
version: '0'
|
|
56
|
-
- !ruby/object:Gem::Dependency
|
|
57
|
-
name: rack-test
|
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
|
59
|
-
requirements:
|
|
60
|
-
- - ">="
|
|
61
|
-
- !ruby/object:Gem::Version
|
|
62
|
-
version: '0'
|
|
63
|
-
type: :development
|
|
64
|
-
prerelease: false
|
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
-
requirements:
|
|
67
|
-
- - ">="
|
|
68
|
-
- !ruby/object:Gem::Version
|
|
69
|
-
version: '0'
|
|
70
|
-
- !ruby/object:Gem::Dependency
|
|
71
|
-
name: rake
|
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
|
73
|
-
requirements:
|
|
74
|
-
- - ">="
|
|
75
|
-
- !ruby/object:Gem::Version
|
|
76
|
-
version: '0'
|
|
77
|
-
type: :development
|
|
78
|
-
prerelease: false
|
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
-
requirements:
|
|
81
|
-
- - ">="
|
|
82
|
-
- !ruby/object:Gem::Version
|
|
83
|
-
version: '0'
|
|
84
|
-
- !ruby/object:Gem::Dependency
|
|
85
|
-
name: rspec
|
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
|
87
|
-
requirements:
|
|
88
|
-
- - ">="
|
|
89
|
-
- !ruby/object:Gem::Version
|
|
90
|
-
version: '0'
|
|
91
|
-
type: :development
|
|
92
|
-
prerelease: false
|
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
94
|
-
requirements:
|
|
95
|
-
- - ">="
|
|
96
|
-
- !ruby/object:Gem::Version
|
|
97
|
-
version: '0'
|
|
98
|
-
- !ruby/object:Gem::Dependency
|
|
99
|
-
name: rubocop-bsm
|
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
|
101
|
-
requirements:
|
|
102
|
-
- - ">="
|
|
103
|
-
- !ruby/object:Gem::Version
|
|
104
|
-
version: '0'
|
|
105
|
-
type: :development
|
|
106
|
-
prerelease: false
|
|
107
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
108
|
-
requirements:
|
|
109
|
-
- - ">="
|
|
110
|
-
- !ruby/object:Gem::Version
|
|
111
|
-
version: '0'
|
|
112
56
|
description: kaminari paginator integration for grape API framework
|
|
113
57
|
email:
|
|
114
58
|
- info@blacksquaremedia.com
|
|
@@ -130,9 +74,6 @@ files:
|
|
|
130
74
|
- lib/grape/kaminari.rb
|
|
131
75
|
- lib/grape/kaminari/max_value_validator.rb
|
|
132
76
|
- lib/grape/kaminari/version.rb
|
|
133
|
-
- spec/grape/kaminari_params_spec.rb
|
|
134
|
-
- spec/grape/kaminari_spec.rb
|
|
135
|
-
- spec/spec_helper.rb
|
|
136
77
|
homepage: ''
|
|
137
78
|
licenses:
|
|
138
79
|
- MIT
|
|
@@ -153,11 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
153
94
|
- !ruby/object:Gem::Version
|
|
154
95
|
version: '0'
|
|
155
96
|
requirements: []
|
|
156
|
-
rubygems_version: 3.
|
|
97
|
+
rubygems_version: 3.3.3
|
|
157
98
|
signing_key:
|
|
158
99
|
specification_version: 4
|
|
159
100
|
summary: kaminari integration for grape
|
|
160
|
-
test_files:
|
|
161
|
-
- spec/grape/kaminari_params_spec.rb
|
|
162
|
-
- spec/grape/kaminari_spec.rb
|
|
163
|
-
- spec/spec_helper.rb
|
|
101
|
+
test_files: []
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'json'
|
|
3
|
-
|
|
4
|
-
describe Grape::Kaminari do
|
|
5
|
-
let(:app) do
|
|
6
|
-
Class.new(Grape::API) do
|
|
7
|
-
include Grape::Kaminari
|
|
8
|
-
|
|
9
|
-
params do
|
|
10
|
-
use :pagination
|
|
11
|
-
end
|
|
12
|
-
get '' do
|
|
13
|
-
paginate(Kaminari.paginate_array((1..10).to_a))
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
params do
|
|
17
|
-
use :pagination, offset: false
|
|
18
|
-
end
|
|
19
|
-
get 'no-offset' do
|
|
20
|
-
paginate(Kaminari.paginate_array((1..10).to_a))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
params do
|
|
24
|
-
use :pagination, offset: false
|
|
25
|
-
end
|
|
26
|
-
get 'no-count' do
|
|
27
|
-
paginate(Kaminari.paginate_array((1..10).to_a), without_count: true)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
resource :sub do
|
|
31
|
-
params do
|
|
32
|
-
use :pagination, per_page: 2
|
|
33
|
-
end
|
|
34
|
-
get '/' do
|
|
35
|
-
paginate(Kaminari.paginate_array((1..10).to_a))
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
let(:json) { JSON.parse(last_response.body) }
|
|
41
|
-
let(:header) { last_response.header }
|
|
42
|
-
|
|
43
|
-
describe 'paginated helper' do
|
|
44
|
-
it 'returns the first page' do
|
|
45
|
-
get '/', page: 1, per_page: 3
|
|
46
|
-
expect(json).to eq [1, 2, 3]
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'returns the second page' do
|
|
50
|
-
get '/', page: 2, per_page: 3
|
|
51
|
-
expect(json).to eq [4, 5, 6]
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# This is here to ensure that Kaminari can handle `padding(false)`
|
|
55
|
-
# and still do the right thing.
|
|
56
|
-
it 'works when offset is false' do
|
|
57
|
-
get '/no-offset', page: 1, per_page: 3
|
|
58
|
-
expect(json).to eq [1, 2, 3]
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it 'works without count' do
|
|
62
|
-
get '/no-count', page: 2, per_page: 3
|
|
63
|
-
expect(json).to eq [4, 5, 6]
|
|
64
|
-
expect(header).to include(
|
|
65
|
-
'X-Per-Page' => '3',
|
|
66
|
-
'X-Page' => '2',
|
|
67
|
-
'X-Next-Page' => '3',
|
|
68
|
-
'X-Prev-Page' => '1',
|
|
69
|
-
)
|
|
70
|
-
expect(header).not_to include(
|
|
71
|
-
'X-Total',
|
|
72
|
-
'X-Total-Pages',
|
|
73
|
-
)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it 'sets headers' do
|
|
77
|
-
get '/', page: 3, per_page: 2, offset: 1
|
|
78
|
-
expect(header).to include(
|
|
79
|
-
'X-Total' => '10',
|
|
80
|
-
'X-Total-Pages' => '5',
|
|
81
|
-
'X-Per-Page' => '2',
|
|
82
|
-
'X-Page' => '3',
|
|
83
|
-
'X-Next-Page' => '4',
|
|
84
|
-
'X-Prev-Page' => '2',
|
|
85
|
-
'X-Offset' => '1',
|
|
86
|
-
)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'can be inherited' do
|
|
90
|
-
get '/sub', page: 1
|
|
91
|
-
expect(json).to eq [1, 2]
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
data/spec/grape/kaminari_spec.rb
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Grape::Kaminari do
|
|
4
|
-
subject do
|
|
5
|
-
Class.new(Grape::API) do
|
|
6
|
-
include Grape::Kaminari
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def declared_params
|
|
11
|
-
subject.namespace_stackable(:declared_params).flatten
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'adds to declared parameters' do
|
|
15
|
-
subject.params { use :pagination }
|
|
16
|
-
expect(declared_params).to eq(%i[page per_page offset])
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it 'may exclude :offset' do
|
|
20
|
-
subject.params { use :pagination, offset: false }
|
|
21
|
-
expect(declared_params).to eq(%i[page per_page])
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it 'supports legacy declarations' do
|
|
25
|
-
subject.paginate
|
|
26
|
-
expect(declared_params).to eq(%i[page per_page offset])
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'does not stumble across repeated declarations' do
|
|
30
|
-
subject.paginate offset: false
|
|
31
|
-
subject.params do
|
|
32
|
-
optional :extra
|
|
33
|
-
end
|
|
34
|
-
expect(declared_params).to eq(%i[page per_page extra])
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe 'descriptions, validation, and defaults' do
|
|
38
|
-
let(:params) { subject.routes.first.params }
|
|
39
|
-
|
|
40
|
-
before do
|
|
41
|
-
subject.params { use :pagination }
|
|
42
|
-
subject.get('/') { 'OK' }
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it 'does not require :page' do
|
|
46
|
-
expect(params['page'][:required]).to eq(false)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'does not require :per_page' do
|
|
50
|
-
expect(params['per_page'][:required]).to eq(false)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it 'does not require :offset' do
|
|
54
|
-
expect(params['offset'][:required]).to eq(false)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it 'describes :page' do
|
|
58
|
-
expect(params['page'][:desc]).to eq('Page offset to fetch.')
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it 'describes :per_page' do
|
|
62
|
-
expect(params['per_page'][:desc]).to eq('Number of results to return per page.')
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it 'describes :offset' do
|
|
66
|
-
expect(params['offset'][:desc]).to eq('Pad a number of results.')
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'validates :page as Integer' do
|
|
70
|
-
expect(params['page'][:type]).to eq('Integer')
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it 'validates :per_page as Integer' do
|
|
74
|
-
expect(params['per_page'][:type]).to eq('Integer')
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it 'validates :offset as Integer' do
|
|
78
|
-
expect(params['offset'][:type]).to eq('Integer')
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it 'defaults :page to 1' do
|
|
82
|
-
expect(params['page'][:default]).to eq(1)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'defaults :per_page to Kaminari.config.default_per_page' do
|
|
86
|
-
expect(params['per_page'][:default]).to eq(::Kaminari.config.default_per_page)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'defaults :offset to 0' do
|
|
90
|
-
expect(params['offset'][:default]).to eq(0)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
describe 'custom paginated api' do
|
|
95
|
-
let(:app) { subject }
|
|
96
|
-
let(:params) { subject.routes.first.params }
|
|
97
|
-
|
|
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
|
-
end
|
|
104
|
-
|
|
105
|
-
it 'defaults :per_page to customized value' do
|
|
106
|
-
expect(params['per_page'][:default]).to eq(99)
|
|
107
|
-
end
|
|
108
|
-
|
|
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
|
|
113
|
-
|
|
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
|
|
119
|
-
|
|
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
|
|
125
|
-
|
|
126
|
-
it 'defaults :offset to customized value' do
|
|
127
|
-
expect(params['offset'][:default]).to eq(9)
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'rspec'
|
|
2
|
-
require 'grape-kaminari'
|
|
3
|
-
require 'rack/test'
|
|
4
|
-
|
|
5
|
-
# Requires supporting files with custom matchers and macros, etc,
|
|
6
|
-
# in ./support/ and its subdirectories.
|
|
7
|
-
Dir[File.expand_path('./support/**/*.rb', __dir__)].sort.each {|f| require f }
|
|
8
|
-
|
|
9
|
-
I18n.enforce_available_locales = false
|
|
10
|
-
|
|
11
|
-
RSpec.configure do |config|
|
|
12
|
-
config.include Rack::Test::Methods
|
|
13
|
-
config.raise_errors_for_deprecations!
|
|
14
|
-
config.order = 'random'
|
|
15
|
-
end
|