Sha256: 3bbe1ab9831ba587e0b031bc232e07965e7418a8c4d34185e7f845d49421a605
Contents?: true
Size: 1.32 KB
Versions: 2
Compression:
Stored size: 1.32 KB
Contents
require 'spec_helper' class PaginatedAPI < Grape::API include Grape::Kaminari paginate get '' do paginate(Kaminari.paginate_array((1..10).to_a)) end paginate offset: false get 'no-offset' do paginate(Kaminari.paginate_array((1..10).to_a)) end end describe Grape::Kaminari do subject { PaginatedAPI.new } def app; subject; end let(:json) { JSON.parse(last_response.body) } let(:header) { last_response.header } describe 'paginated helper' do it 'returns the first page' do get '/', page: 1, per_page: 3 expect(json).to eq [1, 2, 3] end it 'returns the second page' do get '/', page: 2, per_page: 3 expect(json).to eq [4, 5, 6] end # This is here to ensure that Kaminari can handle `padding(false)` # and still do the right thing. it 'works when offset is false' do get '/no-offset', page: 1, per_page: 3 expect(json).to eq [1, 2, 3] end it 'sets headers' do get '/', page: 3, per_page: 2, offset: 1 expect(header['X-Total']).to eq '10' expect(header['X-Total-Pages']).to eq '5' expect(header['X-Per-Page']).to eq '2' expect(header['X-Page']).to eq '3' expect(header['X-Next-Page']).to eq '4' expect(header['X-Prev-Page']).to eq '2' expect(header['X-Offset']).to eq '1' end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
grape-kaminari-0.1.7 | spec/paginate_helper_spec.rb |
grape-kaminari-0.1.6 | spec/paginate_helper_spec.rb |