-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refs #108]
- Loading branch information
Showing
3 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
require_relative '../test_helper' | ||
require 'pagy/extras/countless' | ||
|
||
SingleCov.covered! | ||
|
||
describe Pagy::Countless do | ||
|
||
let(:backend) { TestController.new } # page = 3, items = 20 | ||
|
||
describe "#finalize" do | ||
|
||
before do | ||
@empty_collection = TestCollection.new([]) | ||
@collection = TestCollection.new(Array(1..59)) | ||
end | ||
|
||
let(:last_page) { 3 } | ||
|
||
it 'jump to 2 page with empty collection' do | ||
proc { Pagy::Countless.new(page: 2).finalize(0) }.must_raise Pagy::OverflowError | ||
end | ||
|
||
it 'first page on empty collection' do | ||
pagy, _ = backend.send(:pagy_countless, @empty_collection, page: 1) | ||
|
||
pagy.items.must_equal 20 | ||
pagy.pages.must_equal 1 | ||
pagy.last.must_equal 1 | ||
pagy.from.must_equal 0 | ||
pagy.to.must_equal 0 | ||
pagy.prev.must_be_nil | ||
pagy.next.must_be_nil | ||
end | ||
|
||
it 'first page' do | ||
pagy, _ = backend.send(:pagy_countless, @collection, page: 1) | ||
pagy.must_be_instance_of Pagy::Countless | ||
|
||
pagy.items.must_equal 20 | ||
pagy.last.must_equal 2 | ||
pagy.pages.must_equal 2 # current + 1. `Countless` does not know real count | ||
pagy.from.must_equal 1 | ||
pagy.to.must_equal 20 | ||
pagy.prev.must_be_nil | ||
pagy.next.must_equal 2 | ||
end | ||
|
||
it 'when only one full page exists' do | ||
pagy, _ = backend.send(:pagy_countless, TestCollection.new(Array(1..20)), page: 1) | ||
|
||
pagy.items.must_equal 20 | ||
pagy.pages.must_equal 1 | ||
pagy.from.must_equal 1 | ||
pagy.to.must_equal 20 | ||
pagy.prev.must_be_nil | ||
pagy.next.must_be_nil | ||
end | ||
|
||
it 'when only one not full page exists' do | ||
pagy, _ = backend.send(:pagy_countless, TestCollection.new(Array(1..4)), page: 1) | ||
|
||
pagy.items.must_equal 4 | ||
pagy.pages.must_equal 1 | ||
pagy.from.must_equal 1 | ||
pagy.to.must_equal 4 | ||
pagy.prev.must_be_nil | ||
pagy.next.must_be_nil | ||
|
||
end | ||
|
||
it 'when last page has less records then var[:items]' do | ||
pagy, _ = backend.send(:pagy_countless, @collection, page: last_page) | ||
|
||
pagy.items.must_equal 19 | ||
pagy.pages.must_equal last_page | ||
pagy.from.must_equal 41 | ||
pagy.to.must_equal 59 | ||
pagy.prev.must_equal(last_page - 1) | ||
pagy.next.must_be_nil | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters