Skip to content

Commit 3b6ae63

Browse files
committed
make spec match new api, reflections spec does not apply to pagy
1 parent a27f3a3 commit 3b6ae63

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

spec/active_record_spec.rb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
shared_examples 'produces_correct_sql' do
1313
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)
1717
end
1818
end
1919

2020
describe 'ActiveRecord Support' do
2121
let(:collection) { Foo.all }
22+
let(:collection_size) { 50 }
2223
let(:per_page) { 5 }
2324

2425
if ApiPagination.config.paginator == :will_paginate
@@ -29,16 +30,19 @@
2930
include_examples 'produces_correct_sql'
3031
end
3132

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
3833

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
4246
end
4347
end
4448
end

0 commit comments

Comments
 (0)