Skip to content

Commit

Permalink
fix :last_page mode in out_of_range extra (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jul 14, 2018
1 parent 5958dc5 commit 36761a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/pagy/extras/out_of_range.rb
Expand Up @@ -12,7 +12,9 @@ def initialize(vars)
@out_of_range = true # adds the out_of_range flag
raise e if @vars[:out_of_range_mode] == :exception
if @vars[:out_of_range_mode] == :last_page
@page = @last # set as the last page
page = @vars[:page] # save the very initial page (even after re-run)
super(vars.merge!(page: @last)) # re-run with the last page
@vars[:page] = page # restore the inital page
elsif @vars[:out_of_range_mode] == :empty_page
@offset = @items = @from = @to = 0 # vars relative to the actual page
@prev = @last
Expand Down
5 changes: 5 additions & 0 deletions test/pagy/extras/out_of_range_test.rb
Expand Up @@ -33,6 +33,11 @@
pagy.must_be_instance_of Pagy
pagy.page.must_equal pagy.last
pagy.vars[:page].must_equal 100
pagy.offset.must_equal 100
pagy.items.must_equal 3
pagy.from.must_equal 101
pagy.to.must_equal 103
pagy.prev.must_equal 10
end

it 'raises OutOfRangeError in :exception mode' do
Expand Down

0 comments on commit 36761a8

Please sign in to comment.