mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
Add tests for max_pages and max_pages_per
This commit is contained in:
parent
c1807031ac
commit
13bc89a554
3 changed files with 58 additions and 0 deletions
|
@ -73,4 +73,19 @@ describe Kaminari::Configuration do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'max_pages' do
|
||||
context 'by default' do
|
||||
its(:max_pages) { should == nil }
|
||||
end
|
||||
context 'configure via config block' do
|
||||
before do
|
||||
Kaminari.configure {|c| c.max_pages = 5}
|
||||
end
|
||||
its(:max_pages) { should == 5 }
|
||||
after do
|
||||
Kaminari.configure {|c| c.max_pages = nil}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
23
spec/models/active_record/max_pages_spec.rb
Normal file
23
spec/models/active_record/max_pages_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'spec_helper'
|
||||
|
||||
if defined? ActiveRecord
|
||||
|
||||
describe 'max pages' do
|
||||
describe 'AR::Base' do
|
||||
subject { ActiveRecord::Base }
|
||||
it { should_not respond_to :max_pages_per }
|
||||
end
|
||||
|
||||
subject { User.page 0 }
|
||||
|
||||
context 'by default' do
|
||||
its(:max_pages) { should == nil }
|
||||
end
|
||||
|
||||
context 'when explicitly set via max_pages_per' do
|
||||
before { User.max_pages_per 3 }
|
||||
its(:max_pages) { should == 3 }
|
||||
after { User.max_pages_per nil }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -98,6 +98,26 @@ if defined? ActiveRecord
|
|||
subject { model_class.page(5).per('aho') }
|
||||
its(:total_pages) { should == 4 }
|
||||
end
|
||||
|
||||
context 'with max_pages < total pages count from database' do
|
||||
before { model_class.max_pages_per 3 }
|
||||
subject { model_class.page }
|
||||
its(:total_pages) { should == 3 }
|
||||
after { model_class.max_pages_per nil }
|
||||
end
|
||||
|
||||
context 'with max_pages > total pages count from database' do
|
||||
before { model_class.max_pages_per 11 }
|
||||
subject { model_class.page }
|
||||
its(:total_pages) { should == 4 }
|
||||
after { model_class.max_pages_per nil }
|
||||
end
|
||||
|
||||
context 'with max_pages is nil' do
|
||||
before { model_class.max_pages_per nil }
|
||||
subject { model_class.page }
|
||||
its(:total_pages) { should == 4 }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue