diff --git a/README.md b/README.md index 09be5e92e..fbfdce417 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Please check the [Benchmarks and Memory Profiles Source](http://github.com/ddnex - Pagy is very modular and does not load nor execute unnecessary code in your app _(see [why...](https://ddnexus.github.io/pagy/how-to#global-configuration))_ - It works with collections/scopes that already used `limit` and `offset` _(see [how...](https://ddnexus.github.io/pagy/how-to#paginate-a-pre-offsetted-and-pre-limited-collection))_ - It works with helpers or templates _(see [more...](https://ddnexus.github.io/pagy/how-to#using-templates))_ -- It raises real `Pagy::OutOfRangeError` exceptions that you can rescue from _(see [how...](https://ddnexus.github.io/pagy/how-to#handling-pagyoutofrangeerror-exception))_ or use the [out_of_range extra](http://ddnexus.github.io/pagy/extras/out_of_range) for a few ready to use common behaviors +- It raises real `Pagy::OverflowError` exceptions that you can rescue from _(see [how...](https://ddnexus.github.io/pagy/how-to#handling-pagyoutofrangeerror-exception))_ or use the [overflow extra](http://ddnexus.github.io/pagy/extras/overflow) for a few ready to use common behaviors - It does not impose any difficult-to-override logic or output _(see [why...](https://ddnexus.github.io/pagy/index#really-easy-to-customize))_ ### Easy to use @@ -108,7 +108,7 @@ Use the official extras, or write your own in just a few lines. Extras add speci - [i18n](http://ddnexus.github.io/pagy/extras/i18n): Use the `I18n` gem instead of the pagy implementation - [items](http://ddnexus.github.io/pagy/extras/items): Allow the client to request a custom number of items per page with an optional selector UI -- [out_of_range](http://ddnexus.github.io/pagy/extras/out_of_range): Allow for easy handling of out of range pages +- [overflow](http://ddnexus.github.io/pagy/extras/overflow): Allow for easy handling of overflowing pages - [trim](http://ddnexus.github.io/pagy/extras/trim): Remove the `page=1` param from the first page link ### Alternative components diff --git a/Rakefile b/Rakefile index da4e2d357..fc04fc430 100644 --- a/Rakefile +++ b/Rakefile @@ -10,7 +10,7 @@ require "rubocop/rake_task" Rake::TestTask.new(:test_common) do |t| t.libs << "test" t.libs << "lib" - t.test_files = FileList.new.include("test/**/*_test.rb").exclude('test/**/i18n_test.rb', 'test/**/items_test.rb', 'test/**/out_of_range_test.rb', 'test/**/trim_test.rb') + t.test_files = FileList.new.include("test/**/*_test.rb").exclude('test/**/i18n_test.rb', 'test/**/items_test.rb', 'test/**/overflow_test.rb', 'test/**/trim_test.rb') end Rake::TestTask.new(:test_extra_i18n) do |t| @@ -25,10 +25,10 @@ Rake::TestTask.new(:test_extra_items) do |t| t.test_files = FileList['test/**/items_test.rb'] end -Rake::TestTask.new(:test_extra_out_of_range) do |t| +Rake::TestTask.new(:test_extra_overflow) do |t| t.libs << "test" t.libs << "lib" - t.test_files = FileList['test/**/out_of_range_test.rb'] + t.test_files = FileList['test/**/overflow_test.rb'] end Rake::TestTask.new(:test_extra_trim) do |t| @@ -37,7 +37,7 @@ Rake::TestTask.new(:test_extra_trim) do |t| t.test_files = FileList['test/**/trim_test.rb'] end -task :test => [:test_common, :test_extra_items, :test_extra_i18n, :test_extra_out_of_range, :test_extra_trim ] +task :test => [:test_common, :test_extra_items, :test_extra_i18n, :test_extra_overflow, :test_extra_trim ] RuboCop::RakeTask.new(:rubocop) do |t| t.options = `git ls-files -z`.split("\x0") # limit rubocop to the files in the repo diff --git a/docs/_layouts/default.html b/docs/_layouts/default.html index d71d977f9..841cea806 100644 --- a/docs/_layouts/default.html +++ b/docs/_layouts/default.html @@ -40,7 +40,7 @@

{{ site.title | default: site.github.repository_name }}

Foundation

I18n

Items

-

Out Of Range

+

Overflow

Materialize

Navs

Searchkick

diff --git a/docs/extras.md b/docs/extras.md index e0ff01898..219b5a854 100644 --- a/docs/extras.md +++ b/docs/extras.md @@ -5,21 +5,21 @@ title: Extras Pagy comes with a few optional extensions/extras: -| Extra | Description | Links | -| :---------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `array` | Paginate arrays efficiently avoiding expensive array-wrapping and without overriding | [array.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/array.rb), [documentation](extras/array.md) | -| `bootstrap` | Nav, responsive and compact helpers and templates for the Bootstrap [pagination component](https://getbootstrap.com/docs/4.1/components/pagination) | [bootstrap.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/bootstrap.rb), [documentation](extras/bootstrap.md) | -| `bulma` | Nav, responsive and compact helpers and templates for the Bulma [pagination component](https://bulma.io/documentation/components/pagination) | [bulma.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/bulma.rb), [documentation](extras/bulma.md) | -| `elasticsearch_rails` | Paginate `elasticsearch_rails` gem results efficiently | [elasticsearch_rails.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/elasticsearch_rails.rb), [documentation](extras/elasticsearch_rails.md) | -| `foundation` | Nav, responsive and compact helpers and templates for the Foundation [pagination component](https://foundation.zurb.com/sites/docs/pagination.html) | [foundation.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/foundation.rb), [documentation](extras/foundation.md) | -| `i18n` | Use the `I18n` gem instead of the pagy implementation | [i18n.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/i81n.rb), [documentation](extras/i18n.md) | -| `items` | Allow the client to request a custom number of items per page with a ready to use selector UI | [items.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/items.rb), [documentation](extras/items.md) | -| `materialize` | Nav, responsive and compact helpers for the Materialize CSS [pagination component](https://materializecss.com/pagination.html) | [materialize.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/materialize.rb), [documentation](extras/materialize.md) | -| `navs` | Add responsive and compact generic/unstyled nav helpers | [navs.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/navs.rb), [documentation](extras/navs.md) | -| `out_of_range` | Allow for easy handling of out of range pages | [out_of_range.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/out_of_range.rb), [documentation](extras/out_of_range.md) | -| `searchkick` | Paginate arrays efficiently avoiding expensive array-wrapping and without overriding | [searchkick.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/searchkick.rb), [documentation](extras/searchkick.md) | -| `semantic` | Nav helpers for the Semantic UI CSS [pagination component](https://semantic-ui.com/collections/menu.html) | [semantic.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/semantic.rb), [documentation](extras/semantic.md) | -| `trim` | Remove the `page=1` param from links | [trim.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/trim.rb), [documentation](extras/trim.md) | +| Extra | Description | Links | +|:----------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `array` | Paginate arrays efficiently avoiding expensive array-wrapping and without overriding | [array.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/array.rb), [documentation](extras/array.md) | +| `bootstrap` | Nav, responsive and compact helpers and templates for the Bootstrap [pagination component](https://getbootstrap.com/docs/4.1/components/pagination) | [bootstrap.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/bootstrap.rb), [documentation](extras/bootstrap.md) | +| `bulma` | Nav, responsive and compact helpers and templates for the Bulma [pagination component](https://bulma.io/documentation/components/pagination) | [bulma.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/bulma.rb), [documentation](extras/bulma.md) | +| `elasticsearch_rails` | Paginate `elasticsearch_rails` gem results efficiently | [elasticsearch_rails.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/elasticsearch_rails.rb), [documentation](extras/elasticsearch_rails.md) | +| `foundation` | Nav, responsive and compact helpers and templates for the Foundation [pagination component](https://foundation.zurb.com/sites/docs/pagination.html) | [foundation.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/foundation.rb), [documentation](extras/foundation.md) | +| `i18n` | Use the `I18n` gem instead of the pagy implementation | [i18n.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/i81n.rb), [documentation](extras/i18n.md) | +| `items` | Allow the client to request a custom number of items per page with a ready to use selector UI | [items.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/items.rb), [documentation](extras/items.md) | +| `materialize` | Nav, responsive and compact helpers for the Materialize CSS [pagination component](https://materializecss.com/pagination.html) | [materialize.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/materialize.rb), [documentation](extras/materialize.md) | +| `navs` | Add responsive and compact generic/unstyled nav helpers | [navs.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/navs.rb), [documentation](extras/navs.md) | +| `overflow` | Allow for easy handling of overflowing pages | [overflow.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/overflow.rb), [documentation](extras/overflow.md) | +| `searchkick` | Paginate arrays efficiently avoiding expensive array-wrapping and without overriding | [searchkick.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/searchkick.rb), [documentation](extras/searchkick.md) | +| `semantic` | Nav helpers for the Semantic UI CSS [pagination component](https://semantic-ui.com/collections/menu.html) | [semantic.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/semantic.rb), [documentation](extras/semantic.md) | +| `trim` | Remove the `page=1` param from links | [trim.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/trim.rb), [documentation](extras/trim.md) | ## Synopsys diff --git a/docs/extras/out_of_range.md b/docs/extras/out_of_range.md deleted file mode 100644 index 29b82168e..000000000 --- a/docs/extras/out_of_range.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: Out Of Range ---- -# Out Of Range Extra - -This extra allows for easy handling of out of range pages. It internally rescues from the `Pagy::OutOfRangeError` offering a few different ready to use modes, quite useful for UIs and/or APIs. - -## Synopsys - -See [extras](../extras.md) for general usage info. - -In the `pagy.rb` initializer: - -```ruby -require 'pagy/extras/out_of_range' - -# default :last_page (other options :empty_page and :exception ) -Pagy::VARS[:out_of_range_mode] = :last_page -``` - -## Files - -This extra is composed of the [out_of_range.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/out_of_range.rb) file. - -## Variables - -| Variable | Description | Default | -| -------------------- | ------------------------------------------ | ------------ | -| `:out_of_range_mode` | `:last_page`, `empty_page` or `:exception` | `:last_page` | - -As usual, depending on the scope of the customization, you have a couple of options to set the variables: - -As a global default: - -```ruby -Pagy::VARS[:out_of_range_mode] = :empty_page -``` - -For a single instance (overriding the global default): - -```ruby -pagy(scope, out_of_range_mode: :empty_page) -Pagy.new(count:100, out_of_range_mode: :empty_page) -``` - -## Modes - -These are the modes accepted by the `:out_of_range_mode` variable: - -### :last_page - -This is the default mode. It is useful in apps with an UI, in order to avoid to redirect to the last page. - -Regardless the out of range page requested, Pagy will set the page to the last page and paginate exactly as if the last page has been requested. For example: - -```ruby -# no exception passing an out of range page (Default mode :last_page) -pagy = Pagy.new(count: 100, page: 100) - -pagy.out_of_range? #=> true -pagy.vars[:page] #=> 100 (requested page) -pagy.page #=> 5 (current/last page) -pagy.last == pagy.page #=> true -``` - -### :empty_page - -This mode will paginate the actual requested page, which - being out of range - is empty. It is useful with APIs, where the client expects an empty set of results in order to stop requesting further pages. For example: - -```ruby -pagy = Pagy.new(count: 100, page: 100, out_of_range_mode: :empty_page) - -pagy.out_of_range? #=> true -pagy.vars[:page] #=> 100 (requested page) -pagy.page #=> 100 (actual empty page) -pagy.last == pagy.page #=> false -pagy.last #=> 5 -pagy.last == pagy.prev #=> true (the prev page is the last page relative to out of range page) -pagy.next #=> nil -pagy.offset #=> 0 -pagy.from #=> 0 -pagy.to #=> 0 -pagy.series #=> [1, 2, 3, 4, 5] (no string, so no current page highlighted in the UI) -``` - -### :exception - -This mode raises the `Pagy::OutOfRangeError` as usual, so you can rescue from and do what is needed. It is useful when you need to use your own custom mode even in presence of this extra (which would not raise any error). - -## Methods - -### out_of_range? - -Use this method in order to know if the requested page is out of range. The original requested page is available as `pagy.vars[:page]` (useful when used with the `:last_page` mode, in case you want to give some feedback about the rescue to the user/client). diff --git a/docs/extras/overflow.md b/docs/extras/overflow.md new file mode 100644 index 000000000..ad4729fd7 --- /dev/null +++ b/docs/extras/overflow.md @@ -0,0 +1,94 @@ +--- +title: Overflow +--- +# Overflow Extra + +This extra allows for easy handling of overflowing pages. It internally rescues from the `Pagy::OverflowError` offering a few different ready to use modes, quite useful for UIs and/or APIs. + +## Synopsys + +See [extras](../extras.md) for general usage info. + +In the `pagy.rb` initializer: + +```ruby +require 'pagy/extras/overflow' + +# default :last_page (other options :empty_page and :exception ) +Pagy::VARS[:overflow] = :last_page +``` + +## Files + +This extra is composed of the [overflow.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/overflow.rb) file. + +## Variables + +| Variable | Description | Default | +| ------------| -------------------------------------------------------- | ------------ | +| `:overflow` | one of `:last_page`, `:empty_page` or `:exception` modes | `:last_page` | + +As usual, depending on the scope of the customization, you have a couple of options to set the variables: + +As a global default: + +```ruby +Pagy::VARS[:overflow] = :empty_page +``` + +For a single instance (overriding the global default): + +```ruby +pagy(scope, overflow: :empty_page) +Pagy.new(count:100, overflow: :empty_page) +``` + +## Modes + +These are the modes accepted by the `:overflow` variable: + +### :last_page + +This is the default mode. It is useful in apps with an UI, in order to avoid to redirect to the last page. + +Regardless the overflowing page requested, Pagy will set the page to the last page and paginate exactly as if the last page has been requested. For example: + +```ruby +# no exception passing an overflowing page (Default mode :last_page) +pagy = Pagy.new(count: 100, page: 100) + +pagy.overflow? #=> true +pagy.vars[:page] #=> 100 (requested page) +pagy.page #=> 5 (current/last page) +pagy.last == pagy.page #=> true +``` + +### :empty_page + +This mode will paginate the actual requested page, which - being overflowing - is empty. It is useful with APIs, where the client expects an empty set of results in order to stop requesting further pages. For example: + +```ruby +pagy = Pagy.new(count: 100, page: 100, overflow: :empty_page) + +pagy.overflow? #=> true +pagy.vars[:page] #=> 100 (requested page) +pagy.page #=> 100 (actual empty page) +pagy.last == pagy.page #=> false +pagy.last #=> 5 +pagy.last == pagy.prev #=> true (the prev page is the last page relative to the overflowing page) +pagy.next #=> nil +pagy.offset #=> 0 +pagy.from #=> 0 +pagy.to #=> 0 +pagy.series #=> [1, 2, 3, 4, 5] (no string, so no current page highlighted in the UI) +``` + +### :exception + +This mode raises the `Pagy::OverflowError` as usual, so you can rescue from and do what is needed. It is useful when you need to use your own custom mode even in presence of this extra (which would not raise any error). + +## Methods + +### overflow? + +Use this method in order to know if the requested page is overflowing. The original requested page is available as `pagy.vars[:page]` (useful when used with the `:last_page` mode, in case you want to give some feedback about the rescue to the user/client). diff --git a/docs/how-to.md b/docs/how-to.md index bdae6b054..aa1ab50f3 100644 --- a/docs/how-to.md +++ b/docs/how-to.md @@ -418,27 +418,27 @@ You can do so by setting the `:item_path` variable to the path to lookup in the **Notice**: The variables passed to a Pagy object have the precedence over the variables returned by the `pagy_get_vars`. The fastest way is passing a literal string to the `pagy` method, the most convenient way is using `pagy_get_vars`. -## Handling Pagy::OutOfRangeError exceptions +## Handling Pagy::OverflowError exceptions -Pass an out of range `:page` number and Pagy will raise a `Pagy::OutOfRangeError` exception. +Pass an overflowing `:page` number and Pagy will raise a `Pagy::OverflowError` exception. This often happens because users/clients paginate over the end of the record set or records go deleted and a user went to a stale page. -You can handle the exception by using the [out_of_range extra](extras/out_of_range.md) which provides easy and ready to use solutions for a few common cases, or you can rescue the exception manually and do whatever fits better. +You can handle the exception by using the [overflow extra](extras/overflow.md) which provides easy and ready to use solutions for a few common cases, or you can rescue the exception manually and do whatever fits better. Here are a few options for manually handling the error in apps: - Do nothing and let the page render a 500 - Rescue and render a 404 -- Rescue and redirect to the last known page (Notice: the [out_of_range extra](extras/out_of_range.md) provides the same behavior without redirecting) +- Rescue and redirect to the last known page (Notice: the [overflow extra](extras/overflow.md) provides the same behavior without redirecting) ```ruby # in a controller - rescue_from Pagy::OutOfRangeError, with: :redirect_to_last_page + rescue_from Pagy::OverflowError, with: :redirect_to_last_page private def redirect_to_last_page(e) - redirect_to url_for(page: e.pagy.last), notice: "Page ##{params[:page]} is out of range. Showing page #{e.pagy.last} instead." + redirect_to url_for(page: e.pagy.last), notice: "Page ##{params[:page]} is overflowing. Showing page #{e.pagy.last} instead." end ``` diff --git a/lib/config/pagy.rb b/lib/config/pagy.rb index 30283fdb0..4942912f9 100644 --- a/lib/config/pagy.rb +++ b/lib/config/pagy.rb @@ -62,9 +62,9 @@ # Pagy::VARS[:items_param] = :items # default # Pagy::VARS[:max_items] = 100 # default -# Out Of Range: Allow for easy handling of out of range pages -# See https://ddnexus.github.io/pagy/extras/out_of_range -# Pagy::VARS[:out_of_range_mode] = :last_page # default (other options: :empty_page and :exception) +# Overflow: Allow for easy handling of overflowing pages +# See https://ddnexus.github.io/pagy/extras/overflow +# Pagy::VARS[:overflow] = :last_page # default (other options: :empty_page and :exception) # Trim: Remove the page=1 param from links # See https://ddnexus.github.io/pagy/extras/trim diff --git a/lib/pagy.rb b/lib/pagy.rb index 52690e17c..02f0c587d 100644 --- a/lib/pagy.rb +++ b/lib/pagy.rb @@ -5,7 +5,7 @@ class Pagy ; VERSION = '1.0.0' - class OutOfRangeError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end + class OverflowError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end # Root pathname to get the path of Pagy files like templates or dictionaries def self.root; Pathname.new(__FILE__).dirname end @@ -23,7 +23,7 @@ def initialize(vars) or raise(ArgumentError, "expected :#{k} >= #{min}; got #{@vars[k].inspect}") end @pages = @last = [(@count.to_f / @items).ceil, 1].max # cardinal and ordinal meanings - @page <= @last or raise(OutOfRangeError.new(self), "expected :page in 1..#{@last}; got #{@page.inspect}") + @page <= @last or raise(OverflowError.new(self), "expected :page in 1..#{@last}; got #{@page.inspect}") @offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset) @items = @count - ((@pages-1) * @items) if @page == @last && @count > 0 # adjust items for last non-empty page @from = @count == 0 ? 0 : @offset+1 - @outset # page begins from item diff --git a/lib/pagy/extras/out_of_range.rb b/lib/pagy/extras/overflow.rb similarity index 74% rename from lib/pagy/extras/out_of_range.rb rename to lib/pagy/extras/overflow.rb index bb9f1eef9..878aed61f 100644 --- a/lib/pagy/extras/out_of_range.rb +++ b/lib/pagy/extras/overflow.rb @@ -1,19 +1,19 @@ -# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/out_of_range +# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/overflow # frozen_string_literal: true class Pagy - VARS[:out_of_range_mode] = :last_page + VARS[:overflow] = :last_page - def out_of_range?; @out_of_range end + def overflow?; @overflow end - module OutOfRange + module Overflow def initialize(vars) super - rescue OutOfRangeError - @out_of_range = true # add the out_of_range flag - case @vars[:out_of_range_mode] + rescue OverflowError + @overflow = true # add the overflow flag + case @vars[:overflow] when :exception raise # same as without the extra when :last_page @@ -25,7 +25,7 @@ def initialize(vars) @prev = @last # prev relative to the actual page extend(Series) # special series for :empty_page else - raise ArgumentError, "expected :out_of_range_mode variable in [:last_page, :empty_page, :exception]; got #{@vars[:out_of_range_mode].inspect}" + raise ArgumentError, "expected :overflow variable in [:last_page, :empty_page, :exception]; got #{@vars[:overflow].inspect}" end end @@ -43,6 +43,6 @@ def series(size=@vars[:size]) end - prepend OutOfRange + prepend Overflow end diff --git a/test/pagy/extras/out_of_range_test.rb b/test/pagy/extras/overflow_test.rb similarity index 64% rename from test/pagy/extras/out_of_range_test.rb rename to test/pagy/extras/overflow_test.rb index 1d3b31596..089c22d53 100644 --- a/test/pagy/extras/out_of_range_test.rb +++ b/test/pagy/extras/overflow_test.rb @@ -1,6 +1,6 @@ require 'pagy' require_relative '../../test_helper' -require 'pagy/extras/out_of_range' +require 'pagy/extras/overflow' SingleCov.covered! @@ -12,16 +12,16 @@ describe "variables" do it 'has vars defaults' do - Pagy::VARS[:out_of_range_mode].must_equal :last_page + Pagy::VARS[:overflow].must_equal :last_page end end - describe "#out_of_range?" do + describe "#overflow?" do - it 'must be out_of_range?' do - pagy.must_be :out_of_range? - Pagy.new(vars.merge(page:2)).wont_be :out_of_range? + it 'must be overflow?' do + pagy.must_be :overflow? + Pagy.new(vars.merge(page:2)).wont_be :overflow? end end @@ -40,12 +40,12 @@ pagy.prev.must_equal 10 end - it 'raises OutOfRangeError in :exception mode' do - proc { Pagy.new(vars.merge(out_of_range_mode: :exception)) }.must_raise Pagy::OutOfRangeError + it 'raises OverflowError in :exception mode' do + proc { Pagy.new(vars.merge(overflow: :exception)) }.must_raise Pagy::OverflowError end it 'works in :empty_page mode' do - pagy = Pagy.new(vars.merge(out_of_range_mode: :empty_page)) + pagy = Pagy.new(vars.merge(overflow: :empty_page)) pagy.page.must_equal 100 pagy.offset.must_equal 0 pagy.items.must_equal 0 @@ -55,7 +55,7 @@ end it 'raises ArgumentError' do - proc { Pagy.new(vars.merge(out_of_range_mode: :unknown)) }.must_raise ArgumentError + proc { Pagy.new(vars.merge(overflow: :unknown)) }.must_raise ArgumentError end end @@ -63,7 +63,7 @@ describe "#series singleton for :empty_page mode" do it 'computes series for last page' do - pagy = Pagy.new(vars.merge(out_of_range_mode: :empty_page)) + pagy = Pagy.new(vars.merge(overflow: :empty_page)) series = pagy.series series.must_equal [1, 2, 3, :gap, 9, 10, 11] pagy.page.must_equal 100 diff --git a/test/pagy_test.rb b/test/pagy_test.rb index 5aaf4955a..73a209df2 100644 --- a/test/pagy_test.rb +++ b/test/pagy_test.rb @@ -28,8 +28,8 @@ proc { Pagy.new(count: 100, page: 2, items: 0) }.must_raise ArgumentError proc { Pagy.new(count: 100, page: 2, size: [1, 2, 3]).series }.must_raise ArgumentError proc { Pagy.new(count: 100, page: 2, size: [1, 2, 3, '4']).series }.must_raise ArgumentError - proc { Pagy.new(count: 100, page: '11') }.must_raise Pagy::OutOfRangeError - e = proc { Pagy.new(count: 100, page: 12) }.must_raise Pagy::OutOfRangeError + proc { Pagy.new(count: 100, page: '11') }.must_raise Pagy::OverflowError + e = proc { Pagy.new(count: 100, page: 12) }.must_raise Pagy::OverflowError e.pagy.must_be_instance_of Pagy end