|
5 | 5 | let(:paginate_array_options) {{ total_count: 1000 }} |
6 | 6 |
|
7 | 7 | describe "#paginate" do |
8 | | - context 'Using kaminari' do |
9 | | - before do |
10 | | - ApiPagination.config.paginator = :kaminari |
11 | | - end |
12 | | - |
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 |
| 8 | + if ENV['PAGINATOR'].to_sym == :kaminari |
| 9 | + context 'Using kaminari' do |
| 10 | + it 'should accept paginate_array_options option' do |
| 11 | + expect(Kaminari).to receive(:paginate_array) |
| 12 | + .with(collection, paginate_array_options) |
| 13 | + .and_call_original |
| 14 | + |
| 15 | + ApiPagination.paginate( |
| 16 | + collection, |
| 17 | + { |
| 18 | + per_page: 30, |
| 19 | + paginate_array_options: paginate_array_options |
| 20 | + } |
| 21 | + ) |
| 22 | + end |
30 | 23 |
|
31 | | - describe '.pages_from' do |
32 | | - subject {described_class.pages_from collection} |
| 24 | + describe '.pages_from' do |
| 25 | + subject {described_class.pages_from collection} |
33 | 26 |
|
34 | | - context 'on empty collection' do |
35 | | - let(:collection) {ApiPagination.paginate [], page: 1} |
| 27 | + context 'on empty collection' do |
| 28 | + let(:collection) {ApiPagination.paginate [], page: 1} |
36 | 29 |
|
37 | | - it {is_expected.to be_empty} |
| 30 | + it {is_expected.to be_empty} |
| 31 | + end |
38 | 32 | end |
39 | 33 | end |
40 | 34 | end |
41 | 35 |
|
42 | | - context 'Using will_paginate' do |
43 | | - before do |
44 | | - ApiPagination.config.paginator = :will_paginate |
45 | | - end |
46 | | - |
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) |
| 36 | + if ENV['PAGINATOR'].to_sym == :will_paginate |
| 37 | + context 'Using will_paginate' do |
| 38 | + context 'passing in total_entries in options' do |
| 39 | + it 'should set total_entries using the passed in value' do |
| 40 | + paginated_collection = ApiPagination.paginate(collection, total_entries: 3000) |
| 41 | + expect(paginated_collection.total_entries).to eq(3000) |
| 42 | + end |
55 | 43 | end |
56 | | - end |
57 | 44 |
|
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) |
| 45 | + context 'passing in collection only' do |
| 46 | + it 'should set total_entries using the size of the collection ' do |
| 47 | + paginated_collection = ApiPagination.paginate(collection) |
| 48 | + expect(paginated_collection.total_entries).to eq(100) |
| 49 | + end |
62 | 50 | end |
63 | 51 | end |
64 | 52 | end |
|
0 commit comments