|
11 | 11 |
|
12 | 12 | shared_examples 'produces_correct_sql' do |
13 | 13 | it 'produces correct sql for first page' do |
14 | | - paginated_sql = ApiPagination.paginate(collection, per_page: per_page) |
15 | | - .to_sql |
16 | | - expect(paginated_sql).to eql(Foo.limit(per_page).offset(0).to_sql) |
| 14 | + allow(collection).to receive(:count).and_return(collection_size) |
| 15 | + paginated_sql, _ = ApiPagination.paginate(collection, per_page: per_page) |
| 16 | + expect(paginated_sql.to_sql).to eql(Foo.limit(per_page).offset(0).to_sql) |
17 | 17 | end |
18 | 18 | end |
19 | 19 |
|
20 | 20 | describe 'ActiveRecord Support' do |
21 | 21 | let(:collection) { Foo.all } |
| 22 | + let(:collection_size) { 50 } |
22 | 23 | let(:per_page) { 5 } |
23 | 24 |
|
24 | 25 | if ApiPagination.config.paginator == :will_paginate |
|
29 | 30 | include_examples 'produces_correct_sql' |
30 | 31 | end |
31 | 32 |
|
32 | | - context 'reflections' do |
33 | | - it 'invokes the correct methods to determine type' do |
34 | | - expect(collection).to receive(:klass).at_least(:once) |
35 | | - .and_call_original |
36 | | - ApiPagination.paginate(collection) |
37 | | - end |
38 | 33 |
|
39 | | - it 'does not fail if table name is not snake cased class name' do |
40 | | - allow(collection).to receive(:table_name).and_return(SecureRandom.uuid) |
41 | | - expect { ApiPagination.paginate(collection) }.to_not raise_error |
| 34 | + if ApiPagination.config.paginator != :pagy |
| 35 | + context 'reflections' do |
| 36 | + it 'invokes the correct methods to determine type' do |
| 37 | + expect(collection).to receive(:klass).at_least(:once) |
| 38 | + .and_call_original |
| 39 | + ApiPagination.paginate(collection) |
| 40 | + end |
| 41 | + |
| 42 | + it 'does not fail if table name is not snake cased class name' do |
| 43 | + allow(collection).to receive(:table_name).and_return(SecureRandom.uuid) |
| 44 | + expect { ApiPagination.paginate(collection) }.to_not raise_error |
| 45 | + end |
42 | 46 | end |
43 | 47 | end |
44 | 48 | end |
|
0 commit comments