|
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 |
11 | 12 |
|
12 |
| - after do |
13 |
| - ApiPagination.config.paginator = ENV['PAGINATOR'].to_sym |
14 |
| - end |
| 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 |
15 | 30 |
|
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 |
| - ) |
| 31 | + describe '.pages_from' do |
| 32 | + subject {described_class.pages_from collection} |
| 33 | + |
| 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 |
28 | 40 | end
|
29 | 41 |
|
30 |
| - describe '.pages_from' do |
31 |
| - subject { described_class.pages_from collection } |
| 42 | + context 'Using will_paginate' do |
| 43 | + before do |
| 44 | + ApiPagination.config.paginator = :will_paginate |
| 45 | + end |
32 | 46 |
|
33 |
| - context 'on empty collection' do |
34 |
| - let(:collection) { ApiPagination.paginate [], page: 1 } |
| 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 |
35 | 57 |
|
36 |
| - it { is_expected.to be_empty } |
| 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 |
37 | 63 | end
|
38 | 64 | end
|
39 | 65 | end
|
|
0 commit comments