grape-kaminari 0.2.1 → 0.4.2

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
  SHA256:
3
- metadata.gz: d0ae809ad4c135dcf91437d3e66be5aeade55263df274f958da45e3518643121
4
- data.tar.gz: 6444fd46138c8e330a9c74254f27d0512ea861df07eb90cde07f070a1e43a0e6
3
+ metadata.gz: 5282850782bd08c0a0719eaad85f84b406f1a7419b9755162f939dc7f7aa71bc
4
+ data.tar.gz: 1fbe1503fe2149f82413c3e934452c85bfe190657077fbd1607e6a10beb812b2
5
5
  SHA512:
6
- metadata.gz: 5633fb0d0acecfe2aa68eaff97e29aabddd087922b0ab17a439b26a6fd8ac3889f5f3c902dff54b1729bace30fe6c81c2972a1075785653ea0785b5326ad79e0
7
- data.tar.gz: 25fbc7a3ad61bc457e237da7ccf9dfbced16c76b291cec006ed45ac9504fc9e208d3f5ac2e3f30f9f94396d7b157214f106aeec05bd8d121e1b6ee06e614025a
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/CHANGELOG.md ADDED
@@ -0,0 +1,48 @@
1
+ ### 0.5.0 (Next)
2
+
3
+ #### Features
4
+
5
+ * Your contribution here.
6
+
7
+ #### Fixes
8
+
9
+ * Your contribution here.
10
+
11
+ ### 0.4.1
12
+
13
+ #### Features
14
+
15
+ * [#58](https://github.com/bsm/grape-kaminari/pull/58): Allow to paginate without counting - [@dim](https://github.com/dim).
16
+
17
+ ### 0.4.0
18
+
19
+ #### Features
20
+
21
+ * [#57](https://github.com/bsm/grape-kaminari/pull/57): Introduce new params based API - [@dim](https://github.com/dim).
22
+ * [#56](https://github.com/bsm/grape-kaminari/pull/56): Introduce a CHANGELOG - [@dim](https://github.com/dim).
23
+
24
+ #### Fixes
25
+
26
+ * [#57](https://github.com/bsm/grape-kaminari/pull/57): Fix issues related to Grape v1.5 release - [@dim](https://github.com/dim).
27
+
28
+ ### 0.3.0 (2020/08/10)
29
+
30
+ * [#54](https://github.com/bsm/grape-kaminari/pull/54): Inherit paginate helper - [@dim](https://github.com/dim).
31
+
32
+ ### 0.2.1 (2020/06/18)
33
+
34
+ #### Fixes
35
+
36
+ * [#52](https://github.com/bsm/grape-kaminari/pull/52): Skip per-page range validation for non-integer values - [@dim](https://github.com/dim).
37
+
38
+ ### 0.2.0 (2020/06/18)
39
+
40
+ Revived project, migrated to [github.com/bsm/grape-kaminari](github.com/bsm/grape-kaminari).
41
+
42
+ #### Features
43
+
44
+ * [#51](https://github.com/bsm/grape-kaminari/pull/51): Support for Grape 1.x - [@dim](https://github.com/dim).
45
+
46
+ #### Fixes
47
+
48
+ * [#51](https://github.com/bsm/grape-kaminari/pull/51): Fixed code style - [@dim](https://github.com/dim).
data/Gemfile.lock CHANGED
@@ -1,106 +1,119 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape-kaminari (0.2.1)
5
- grape (>= 1.0)
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.0.3.2)
11
+ activesupport (6.1.3.1)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- zeitwerk (~> 2.2, >= 2.2.2)
17
- ast (2.4.1)
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.6)
20
- diff-lcs (1.3)
21
- dry-configurable (0.11.5)
19
+ concurrent-ruby (1.1.8)
20
+ diff-lcs (1.4.4)
21
+ dry-configurable (0.12.1)
22
22
  concurrent-ruby (~> 1.0)
23
- dry-core (~> 0.4, >= 0.4.7)
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.4.9)
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.6)
30
+ dry-logic (1.2.0)
33
31
  concurrent-ruby (~> 1.0)
34
- dry-core (~> 0.2)
35
- dry-equalizer (~> 0.2)
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.4, >= 0.4.4)
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.3.3)
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.3)
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.1)
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.19.2)
62
- parser (2.7.1.3)
63
- ast (~> 2.4.0)
57
+ parallel (1.20.1)
58
+ parser (3.0.1.1)
59
+ ast (~> 2.4.1)
64
60
  rack (2.2.3)
65
61
  rack-accept (0.4.5)
66
62
  rack (>= 0.4)
67
63
  rack-test (1.1.0)
68
64
  rack (>= 1.0, < 3)
69
65
  rainbow (3.0.0)
70
- rake (13.0.1)
71
- regexp_parser (1.7.1)
72
- rexml (3.2.4)
73
- rspec (3.9.0)
74
- rspec-core (~> 3.9.0)
75
- rspec-expectations (~> 3.9.0)
76
- rspec-mocks (~> 3.9.0)
77
- rspec-core (3.9.2)
78
- rspec-support (~> 3.9.3)
79
- rspec-expectations (3.9.2)
66
+ rake (13.0.3)
67
+ regexp_parser (2.1.1)
68
+ rexml (3.2.5)
69
+ rspec (3.10.0)
70
+ rspec-core (~> 3.10.0)
71
+ rspec-expectations (~> 3.10.0)
72
+ rspec-mocks (~> 3.10.0)
73
+ rspec-core (3.10.1)
74
+ rspec-support (~> 3.10.0)
75
+ rspec-expectations (3.10.1)
80
76
  diff-lcs (>= 1.2.0, < 2.0)
81
- rspec-support (~> 3.9.0)
82
- rspec-mocks (3.9.1)
77
+ rspec-support (~> 3.10.0)
78
+ rspec-mocks (3.10.2)
83
79
  diff-lcs (>= 1.2.0, < 2.0)
84
- rspec-support (~> 3.9.0)
85
- rspec-support (3.9.3)
86
- rubocop (0.85.1)
80
+ rspec-support (~> 3.10.0)
81
+ rspec-support (3.10.2)
82
+ rubocop (1.13.0)
87
83
  parallel (~> 1.10)
88
- parser (>= 2.7.0.1)
84
+ parser (>= 3.0.0.0)
89
85
  rainbow (>= 2.2.2, < 4.0)
90
- regexp_parser (>= 1.7)
86
+ regexp_parser (>= 1.8, < 3.0)
91
87
  rexml
92
- rubocop-ast (>= 0.0.3)
88
+ rubocop-ast (>= 1.2.0, < 2.0)
93
89
  ruby-progressbar (~> 1.7)
94
- unicode-display_width (>= 1.4.0, < 2.0)
95
- rubocop-ast (0.0.3)
96
- parser (>= 2.7.0.1)
97
- ruby-progressbar (1.10.1)
98
- ruby2_keywords (0.0.2)
99
- thread_safe (0.3.6)
100
- tzinfo (1.2.7)
101
- thread_safe (~> 0.1)
102
- unicode-display_width (1.7.0)
103
- zeitwerk (2.3.0)
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
- [![Build Status](https://travis-ci.org/bsm/grape-kaminari.png?branch=master)](https://travis-ci.org/bsm/grape-kaminari)
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.
@@ -35,7 +35,6 @@ class MyApi < Grape::API
35
35
  resource :posts do
36
36
  desc 'Return a list of posts.'
37
37
 
38
- # Annotate action with `paginate`.
39
38
  # This will add three optional params: page, per_page, and offset
40
39
  #
41
40
  # You can optionally overwrite the default :per_page setting (10)
@@ -45,8 +44,9 @@ class MyApi < Grape::API
45
44
  # You can disable the offset parameter from appearing in the API
46
45
  # documentation by setting it to false.
47
46
  #
48
- paginate per_page: 20, max_per_page: 30, offset: 5
49
-
47
+ params do
48
+ use :pagination, per_page: 20, max_per_page: 30, offset: 5
49
+ end
50
50
  get do
51
51
  posts = Post.where(...)
52
52
 
@@ -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 { |f| f.start_with?('spec/') }
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.0'
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,5 +1,5 @@
1
1
  module Grape
2
2
  module Kaminari
3
- VERSION = '0.2.1'.freeze
3
+ VERSION = '0.4.2'.freeze
4
4
  end
5
5
  end
@@ -5,47 +5,61 @@ require 'kaminari/grape'
5
5
 
6
6
  module Grape
7
7
  module Kaminari
8
- module HelperMethods # :nodoc:
9
- def paginate(collection)
10
- collection.page(params[:page].to_i)
11
- .per(params[:per_page].to_i)
12
- .padding(params[:offset].to_i)
13
- .tap do |data|
14
- header 'X-Total', data.total_count.to_s
15
- header 'X-Total-Pages', data.total_pages.to_s
16
- header 'X-Per-Page', data.limit_value.to_s
17
- header 'X-Page', data.current_page.to_s
18
- header 'X-Next-Page', data.next_page.to_s
19
- header 'X-Prev-Page', data.prev_page.to_s
20
- header 'X-Offset', params[:offset].to_s
21
- end
22
- end
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ helpers HelperMethods
23
12
  end
24
13
 
25
- module ClassMethods # :nodoc:
26
- def paginate(**options)
27
- options.reverse_merge!(
14
+ module HelperMethods # :nodoc:
15
+ extend Grape::API::Helpers
16
+
17
+ params :pagination do |opts = {}|
18
+ opts.reverse_merge!(
28
19
  per_page: ::Kaminari.config.default_per_page || 10,
29
20
  max_per_page: ::Kaminari.config.max_per_page,
30
21
  offset: 0,
31
22
  )
32
- params do
33
- optional :page, type: Integer, default: 1,
34
- desc: 'Page offset to fetch.'
35
- optional :per_page, type: Integer, default: options[:per_page],
36
- desc: 'Number of results to return per page.',
37
- max_value: options[:max_per_page]
38
- if options[:offset].is_a? Numeric
39
- optional :offset, type: Integer, default: options[:offset],
40
- desc: 'Pad a number of results.'
41
- end
23
+
24
+ optional :page, type: Integer, default: 1,
25
+ desc: 'Page offset to fetch.'
26
+ optional :per_page, type: Integer, default: opts[:per_page],
27
+ desc: 'Number of results to return per page.',
28
+ max_value: opts[:max_per_page]
29
+
30
+ if opts[:offset].is_a?(Integer)
31
+ optional :offset, type: Integer, default: opts[:offset],
32
+ desc: 'Pad a number of results.'
42
33
  end
43
34
  end
35
+
36
+ def paginate(collection, without_count: false)
37
+ coll = collection.page(params[:page].to_i)
38
+ .per(params[:per_page].to_i)
39
+ .padding(params[:offset].to_i)
40
+ coll = coll.without_count if without_count && coll.respond_to?(:without_count)
41
+
42
+ unless without_count
43
+ header 'X-Total', coll.total_count.to_s
44
+ header 'X-Total-Pages', coll.total_pages.to_s
45
+ end
46
+ header 'X-Per-Page', coll.limit_value.to_s
47
+ header 'X-Page', coll.current_page.to_s
48
+ header 'X-Next-Page', coll.next_page.to_s
49
+ header 'X-Prev-Page', coll.prev_page.to_s
50
+ header 'X-Offset', params[:offset].to_s
51
+
52
+ coll
53
+ end
44
54
  end
45
55
 
46
- def self.included(base)
47
- base.helpers HelperMethods
48
- base.extend ClassMethods
56
+ module DSLMethods # :nodoc:
57
+ def paginate(opts = {})
58
+ params do
59
+ use(:pagination, opts)
60
+ end
61
+ end
49
62
  end
63
+ Grape::API::Instance.extend(DSLMethods)
50
64
  end
51
65
  end
@@ -0,0 +1,130 @@
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 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 { |f| require f }
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.2.1
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: 2020-06-18 00:00:00.000000000 Z
12
+ date: 2022-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grape
@@ -17,14 +17,20 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '1.0'
20
+ version: 1.6.1
21
+ - - "!="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.0
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
28
  - - ">="
26
29
  - !ruby/object:Gem::Version
27
- version: '1.0'
30
+ version: 1.6.1
31
+ - - "!="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.0
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: kaminari-grape
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +102,7 @@ dependencies:
96
102
  - !ruby/object:Gem::Version
97
103
  version: '0'
98
104
  - !ruby/object:Gem::Dependency
99
- name: rubocop
105
+ name: rubocop-bsm
100
106
  requirement: !ruby/object:Gem::Requirement
101
107
  requirements:
102
108
  - - ">="
@@ -116,9 +122,10 @@ executables: []
116
122
  extensions: []
117
123
  extra_rdoc_files: []
118
124
  files:
125
+ - ".github/workflows/test.yml"
119
126
  - ".gitignore"
120
127
  - ".rubocop.yml"
121
- - ".travis.yml"
128
+ - CHANGELOG.md
122
129
  - Gemfile
123
130
  - Gemfile.lock
124
131
  - LICENSE.txt
@@ -129,8 +136,7 @@ files:
129
136
  - lib/grape/kaminari.rb
130
137
  - lib/grape/kaminari/max_value_validator.rb
131
138
  - lib/grape/kaminari/version.rb
132
- - spec/kaminari_spec.rb
133
- - spec/paginate_helper_spec.rb
139
+ - spec/grape/kaminari_spec.rb
134
140
  - spec/spec_helper.rb
135
141
  homepage: ''
136
142
  licenses:
@@ -151,11 +157,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
157
  - !ruby/object:Gem::Version
152
158
  version: '0'
153
159
  requirements: []
154
- rubygems_version: 3.1.4
160
+ rubygems_version: 3.2.15
155
161
  signing_key:
156
162
  specification_version: 4
157
163
  summary: kaminari integration for grape
158
164
  test_files:
159
- - spec/kaminari_spec.rb
160
- - spec/paginate_helper_spec.rb
165
+ - spec/grape/kaminari_spec.rb
161
166
  - spec/spec_helper.rb
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.7
5
- - 2.6
6
- - 2.5
@@ -1,130 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class UnPaginatedAPI < Grape::API
4
- # Intentionally not including Grape::Kaminari
5
- end
6
-
7
- class PaginatedAPI < Grape::API
8
- include Grape::Kaminari
9
- end
10
-
11
- describe Grape::Kaminari do
12
- describe 'unpaginated api' do
13
- subject { Class.new(UnPaginatedAPI) }
14
-
15
- it 'raises an error' do
16
- expect { subject.paginate }.to raise_error(NoMethodError, /undefined method `paginate' for/i)
17
- end
18
- end
19
-
20
- describe 'default paginated api' do
21
- subject { Class.new(PaginatedAPI) }
22
-
23
- it 'adds to declared parameters' do
24
- subject.paginate
25
- expect(subject.inheritable_setting.route[:declared_params]).to eq(%i[page per_page offset])
26
- end
27
-
28
- describe 'descriptions, validation, and defaults' do
29
- let(:params) { subject.routes.first.params }
30
-
31
- before do
32
- subject.paginate
33
- subject.get('/') {}
34
- end
35
-
36
- it 'does not require :page' do
37
- expect(params['page'][:required]).to eq(false)
38
- end
39
-
40
- it 'does not require :per_page' do
41
- expect(params['per_page'][:required]).to eq(false)
42
- end
43
-
44
- it 'does not require :offset' do
45
- expect(params['offset'][:required]).to eq(false)
46
- end
47
-
48
- it 'describes :page' do
49
- expect(params['page'][:desc]).to eq('Page offset to fetch.')
50
- end
51
-
52
- it 'describes :per_page' do
53
- expect(params['per_page'][:desc]).to eq('Number of results to return per page.')
54
- end
55
-
56
- it 'describes :offset' do
57
- expect(params['offset'][:desc]).to eq('Pad a number of results.')
58
- end
59
-
60
- it 'validates :page as Integer' do
61
- expect(params['page'][:type]).to eq('Integer')
62
- end
63
-
64
- it 'validates :per_page as Integer' do
65
- expect(params['per_page'][:type]).to eq('Integer')
66
- end
67
-
68
- it 'validates :offset as Integer' do
69
- expect(params['offset'][:type]).to eq('Integer')
70
- end
71
-
72
- it 'defaults :page to 1' do
73
- expect(params['page'][:default]).to eq(1)
74
- end
75
-
76
- it 'defaults :per_page to Kaminari.config.default_per_page' do
77
- expect(params['per_page'][:default]).to eq(::Kaminari.config.default_per_page)
78
- end
79
-
80
- it 'defaults :offset to 0' do
81
- expect(params['offset'][:default]).to eq(0)
82
- end
83
- end
84
- end
85
-
86
- describe 'custom paginated api' do
87
- subject { Class.new(PaginatedAPI) }
88
- let(:app) { subject }
89
- let(:params) { subject.routes.first.params }
90
-
91
- before do
92
- subject.paginate per_page: 99, max_per_page: 999, offset: 9
93
- subject.get('/') {}
94
- end
95
-
96
- it 'defaults :per_page to customized value' do
97
- expect(params['per_page'][:default]).to eq(99)
98
- end
99
-
100
- it 'succeeds when :per_page is within :max_value' do
101
- get('/', page: 1, per_page: 999)
102
- expect(last_response.status).to eq(200)
103
- end
104
-
105
- it 'ensures :per_page is within :max_value' do
106
- get('/', page: 1, per_page: 1_000)
107
- expect(last_response.status).to eq(400)
108
- expect(last_response.body).to match(/per_page must be less than or equal 999/)
109
- end
110
-
111
- it 'ensures :per_page is numeric' do
112
- get('/', page: 1, per_page: 'foo')
113
- expect(last_response.status).to eq(400)
114
- expect(last_response.body).to match(/per_page is invalid/)
115
- end
116
-
117
- it 'defaults :offset to customized value' do
118
- expect(params['offset'][:default]).to eq(9)
119
- end
120
- end
121
-
122
- describe 'paginated api without :offset' do
123
- subject { Class.new(PaginatedAPI) }
124
-
125
- it 'excludes :offset from declared params' do
126
- subject.paginate offset: false
127
- expect(subject.inheritable_setting.route[:declared_params]).not_to include(:offset)
128
- end
129
- end
130
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
- require 'json'
3
-
4
- class PaginatedAPI < Grape::API
5
- include Grape::Kaminari
6
-
7
- paginate
8
- get '' do
9
- paginate(Kaminari.paginate_array((1..10).to_a))
10
- end
11
-
12
- paginate offset: false
13
- get 'no-offset' do
14
- paginate(Kaminari.paginate_array((1..10).to_a))
15
- end
16
- end
17
-
18
- describe Grape::Kaminari do
19
- subject { PaginatedAPI.new }
20
- def app
21
- subject
22
- end
23
- let(:json) { JSON.parse(last_response.body) }
24
- let(:header) { last_response.header }
25
-
26
- describe 'paginated helper' do
27
- it 'returns the first page' do
28
- get '/', page: 1, per_page: 3
29
- expect(json).to eq [1, 2, 3]
30
- end
31
-
32
- it 'returns the second page' do
33
- get '/', page: 2, per_page: 3
34
- expect(json).to eq [4, 5, 6]
35
- end
36
-
37
- # This is here to ensure that Kaminari can handle `padding(false)`
38
- # and still do the right thing.
39
- it 'works when offset is false' do
40
- get '/no-offset', page: 1, per_page: 3
41
- expect(json).to eq [1, 2, 3]
42
- end
43
-
44
- it 'sets headers' do
45
- get '/', page: 3, per_page: 2, offset: 1
46
- expect(header['X-Total']).to eq '10'
47
- expect(header['X-Total-Pages']).to eq '5'
48
- expect(header['X-Per-Page']).to eq '2'
49
- expect(header['X-Page']).to eq '3'
50
- expect(header['X-Next-Page']).to eq '4'
51
- expect(header['X-Prev-Page']).to eq '2'
52
- expect(header['X-Offset']).to eq '1'
53
- end
54
- end
55
- end