|
2 | 2 |
|
3 | 3 | describe ApiPagination do |
4 | 4 | let(:collection) {(1..100).to_a} |
| 5 | + let(:active_record_relation) {double("ActiveRecord_Relation").as_null_object} |
5 | 6 | let(:paginate_array_options) {{ total_count: 1000 }} |
6 | 7 |
|
7 | 8 | describe "#paginate" do |
8 | 9 | if ENV['PAGINATOR'].to_sym == :kaminari |
9 | 10 | 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 | | - ) |
| 11 | + describe '.paginate' do |
| 12 | + it 'should accept paginate_array_options option' do |
| 13 | + expect(Kaminari).to receive(:paginate_array) |
| 14 | + .with(collection, paginate_array_options) |
| 15 | + .and_call_original |
| 16 | + |
| 17 | + ApiPagination.paginate( |
| 18 | + collection, |
| 19 | + { |
| 20 | + per_page: 30, |
| 21 | + paginate_array_options: paginate_array_options |
| 22 | + } |
| 23 | + ) |
| 24 | + end |
| 25 | + |
| 26 | + context 'configured not to include the total' do |
| 27 | + before { ApiPagination.config.include_total = false } |
| 28 | + |
| 29 | + context 'and paginating an array' do |
| 30 | + it 'should not call without_count on the collection' do |
| 31 | + expect(collection).to_not receive :without_count |
| 32 | + ApiPagination.paginate(collection) |
| 33 | + end |
| 34 | + end |
| 35 | + context 'and paginating an active record relation' do |
| 36 | + it 'should call without_count on the relation' do |
| 37 | + expect(active_record_relation).to receive :without_count |
| 38 | + ApiPagination.paginate(active_record_relation) |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + after { ApiPagination.config.include_total = true } |
| 43 | + end |
22 | 44 | end |
23 | 45 |
|
24 | 46 | describe '.pages_from' do |
|
0 commit comments