-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: improved a lot of things, but still incomplete
- Loading branch information
Showing
12 changed files
with
137 additions
and
165 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../test_helper' | ||
require 'pagy/extras/keyset_for_ui' | ||
require 'pagy/extras/limit' | ||
|
||
require_relative '../../files/models' | ||
require_relative '../../mock_helpers/app' | ||
|
||
describe 'pagy/extras/keyset_for_ui' do | ||
[Pet, PetSequel].each do |model| | ||
describe 'pagy_keyset_for_ui' do | ||
it 'works for page 1' do | ||
app = MockApp.new(params: {}) | ||
pagy, records = app.send(:pagy_keyset_for_ui, | ||
model.order(:id), | ||
tuple_comparison: true, | ||
limit: 10) | ||
_(pagy).must_be_kind_of Pagy::KeysetForUI | ||
_(records.size).must_equal 10 | ||
_(pagy.next).must_equal 2 | ||
_(pagy.update).must_equal [nil, 1, 0, [10]] | ||
end | ||
it 'works for page 2' do | ||
app = MockApp.new(params: {cutoffs: Pagy::B64.urlsafe_encode(['key', 2, [10]].to_json)}) | ||
pagy, records = app.send(:pagy_keyset_for_ui, | ||
model.order(:id), | ||
page: 2, | ||
tuple_comparison: true, | ||
limit: 10) | ||
_(pagy).must_be_kind_of Pagy::KeysetForUI | ||
_(records.size).must_equal 10 | ||
_(records.first.id).must_equal 11 | ||
_(pagy.next).must_equal 3 | ||
_(pagy.update).must_equal ['key', 2, 0, [20]] | ||
end | ||
it 'works for page 5' do | ||
app = MockApp.new(params: {cutoffs: Pagy::B64.urlsafe_encode(['key', 5, [40]].to_json)}) | ||
pagy, records = app.send(:pagy_keyset_for_ui, | ||
model.order(:id), | ||
page: 5, | ||
tuple_comparison: true, | ||
limit: 10) | ||
_(pagy).must_be_kind_of Pagy::KeysetForUI | ||
_(records.size).must_equal 10 | ||
_(records.first.id).must_equal 41 | ||
_(pagy.next).must_be_nil | ||
_(pagy.update).must_be_nil | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.