diff --git a/.idea/runConfigurations/Test_Only.xml b/.idea/runConfigurations/Test_Only.xml
new file mode 100644
index 000000000..41b47a2f7
--- /dev/null
+++ b/.idea/runConfigurations/Test_Only.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CHANGELOG-10.md b/CHANGELOG-10.md
index e61f9feb3..fc6c9e987 100644
--- a/CHANGELOG-10.md
+++ b/CHANGELOG-10.md
@@ -103,7 +103,8 @@ Added `Pagy::Javascript.install` function to avoid messing up with complicated j
No setup required. The locales and their pluralization are autoloaded when you app use them.
-The code is simpler and lighter, you can also override the lookup of dictionary files with `Pagy::I18n::PATHNAMES.unshift(Pathname.new('my/customized/dictionaries'))`.
+The code is simpler and lighter, you can also override the lookup of dictionary files with
+`Pagy::I18n::PATHNAMES.unshift(Pathname.new('my/customized/dictionaries'))`.
### Breaking Changes
@@ -137,10 +138,10 @@ to start with the new version of the file.
#### The `Pagy::DEFAULT` is now frozen
-- The `Pagy::DEFAULT` is now an internal hash and it's frozen. If you had any default set there, you should pass the options to
- the paginator constructors.
-- As an alternative to avoid repetitions, define your own default hash and pass it to the different paginator methods/helpers.
-- See the new initializer for details.
+- The `Pagy::DEFAULT` is now an internal hash and it's frozen. If you set any option with it, you should pass them to the
+ paginator methods.
+- As an alternative to avoid repetitions, define your own PAGY_OPTIONS hash and pass it to the different paginator
+ methods/helpers. See the new initializer for details.
#### Core changes
diff --git a/gem/apps/demo.ru b/gem/apps/demo.ru
index 310b0e071..660c38d80 100644
--- a/gem/apps/demo.ru
+++ b/gem/apps/demo.ru
@@ -45,7 +45,7 @@ require 'sinatra/base'
# Sinatra application
class PagyDemo < Sinatra::Base
include Pagy::Backend
- PAGY_DEFAULT = { requestable_limit: 100 }.freeze
+ PAGY_OPTIONS = { requestable_limit: 100 }.freeze
get '/' do
redirect '/pagy'
@@ -53,7 +53,7 @@ class PagyDemo < Sinatra::Base
get '/template' do
collection = MockCollection.new
- @pagy, @records = pagy_offset(collection, **PAGY_DEFAULT)
+ @pagy, @records = pagy_offset(collection, **PAGY_OPTIONS)
erb :template, locals: { pagy: @pagy, style: 'pagy' }
end
@@ -79,7 +79,7 @@ class PagyDemo < Sinatra::Base
get("/#{style}") do
collection = MockCollection.new
- @pagy, @records = pagy_offset(collection, **PAGY_DEFAULT)
+ @pagy, @records = pagy_offset(collection, **PAGY_OPTIONS)
erb :helpers, locals: { style:, prefix: }
end
diff --git a/gem/apps/keynav.ru b/gem/apps/keynav.ru
index 71ec3a7e3..4c681d8c3 100644
--- a/gem/apps/keynav.ru
+++ b/gem/apps/keynav.ru
@@ -35,7 +35,7 @@ require 'sinatra/base'
# Sinatra application
class PagyKeynav < Sinatra::Base
include Pagy::Backend
- PAGY_DEFAULT = { limit: 4, requestable_limit: 100 }.freeze
+ PAGY_OPTIONS = { limit: 4, requestable_limit: 100 }.freeze
get('/javascripts/:file') do
format = params[:file].split('.').last
@@ -52,7 +52,7 @@ class PagyKeynav < Sinatra::Base
Time.zone = 'UTC'
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
- @pagy, @pets = pagy_keynav_js(Pet.order(@order), **PAGY_DEFAULT)
+ @pagy, @pets = pagy_keynav_js(Pet.order(@order), **PAGY_OPTIONS)
@ids = @pets.pluck(:id)
erb :main
end
diff --git a/gem/apps/keyset.ru b/gem/apps/keyset.ru
index af99c18af..ce00f9dee 100644
--- a/gem/apps/keyset.ru
+++ b/gem/apps/keyset.ru
@@ -35,7 +35,7 @@ require 'sinatra/base'
# Sinatra application
class PagyKeyset < Sinatra::Base
include Pagy::Backend
- PAGY_DEFAULT = { limit: 10, requestable_limit: 100 }.freeze
+ PAGY_OPTIONS = { limit: 10, requestable_limit: 100 }.freeze
# Root route/action
get '/' do
diff --git a/gem/apps/keyset_sequel.ru b/gem/apps/keyset_sequel.ru
index f52638ec1..eeb0ad7fb 100644
--- a/gem/apps/keyset_sequel.ru
+++ b/gem/apps/keyset_sequel.ru
@@ -36,7 +36,7 @@ require 'logger'
# Sinatra application
class PagyKeysetSequel < Sinatra::Base
include Pagy::Backend
- PAGY_DEFAULT = { limit: 10, requestable_limit: 100 }.freeze
+ PAGY_OPTIONS = { limit: 10, requestable_limit: 100 }.freeze
# Root route/action
get '/' do
diff --git a/gem/apps/rails.ru b/gem/apps/rails.ru
index 851cfb3bb..9d6cbe952 100644
--- a/gem/apps/rails.ru
+++ b/gem/apps/rails.ru
@@ -106,11 +106,11 @@ end
class CommentsController < ActionController::Base # :nodoc:
include Rails.application.routes.url_helpers
include Pagy::Backend
- PAGY_DEFAULT = { limit: 10,
+ PAGY_OPTIONS = { limit: 10,
requestable_limit: 100 }.freeze
def index
- @pagy, @comments = pagy_offset(Comment.all, **PAGY_DEFAULT)
+ @pagy, @comments = pagy_offset(Comment.all, **PAGY_OPTIONS)
# pagy_headers_merge(@pagy)
render inline: TEMPLATE
end
diff --git a/gem/apps/repro.ru b/gem/apps/repro.ru
index 7e43eb55c..389db3ca6 100644
--- a/gem/apps/repro.ru
+++ b/gem/apps/repro.ru
@@ -37,7 +37,7 @@ require 'sinatra/base'
# Sinatra application
class PagyRepro < Sinatra::Base
include Pagy::Backend
- PAGY_DEFAULT = { requestable_limit: 100 }.freeze
+ PAGY_OPTIONS = { requestable_limit: 100 }.freeze
get('/javascripts/:file') do
format = params[:file].split('.').last
@@ -52,9 +52,9 @@ class PagyRepro < Sinatra::Base
# Edit this action as needed
get '/' do
collection = MockCollection.new
- @pagy, @records = pagy_offset(collection, **PAGY_DEFAULT)
- # @pagy, @records = pagy_countless(collection, **PAGY_DEFAULT)
- # @pagy, @records = pagy_array(Array(1..1000), **PAGY_DEFAULT)
+ @pagy, @records = pagy_offset(collection, **PAGY_OPTIONS)
+ # @pagy, @records = pagy_countless(collection, **PAGY_OPTIONS)
+ # @pagy, @records = pagy_array(Array(1..1000), **PAGY_OPTIONS)
erb :main
end
diff --git a/gem/config/pagy.rb b/gem/config/pagy.rb
index e0fff0e89..6b7b870c2 100644
--- a/gem/config/pagy.rb
+++ b/gem/config/pagy.rb
@@ -6,35 +6,31 @@
###################################### DEFAULT #######################################
# Customizing the static and frozen Pagy::DEFAULT is NOT SUPPORTED anymore!
#
-# As an alternative to avoid repetitions, define your own default hash and pass it
+# As an alternative to avoid repetitions, define your own options hash and pass it
# to the different paginator methods.
# For example:
#
-# PAGY_DEFAULT = { limit: 10 }.freeze
-# pagy_offset(collection, **PAGY_DEFAULT, **other_vars)
-# pagy_keyset(set, **PAGY_DEFAULT, **other_vars)
+# PAGY_OPTIONS = { limit: 10 }.freeze
+# pagy_offset(collection, **PAGY_OPTIONS, **other_options)
+# pagy_keyset(set, **PAGY_OPTIONS, **other_options)
############ Install Pagy Javascript #####################################################
-# If you use any pagy method ending with '*_js',
-# uncomment/customize one of the following:
+# If you use any pagy method ending with '*_js', uncomment/customize one of the following:
# Generic reference to customize
# Available file formats: 'pagy.mjs', 'pagy.js', 'pagy.js.map', 'pagy.min.js'
# Pagy::Javascript.install('pagy.mjs', 'pagy.js', ..., javascript_path) if env_dev
# Example for Rails
-# javascript_path = Rails.root.join('app/javascript')
-# Install all files...
-# Pagy::Javascript.install(javascript_path)) if Rails.env.development?
-# Install only 'pagy.mjs'...
-# Pagy::Javascript.install('pagy.mjs', javascript_path) if Rails.env.development?
+# Install 'pagy.mjs' in the dir 'app/javascript'
+# Pagy::Javascript.install('pagy.mjs', 'app/javascript') if Rails.env.development?
############# Overriding Pagy::I18n dictionary lookup ######################################
# Override the dictionary lookup for customization. Just drop your customized
-# dictionary/dictionaries in a dir and add its pathname to the lookup:
-# Pagy::I18n::PATHNAMES.unshift(Pathname.new('my/customized/dictionaries'))
+# dictionary/dictionaries in a dir and unshift its pathname to the lookup:
+# Pagy::I18n::LOOKUP_PATHNAMES.unshift(Pathname.new('my/customized/dictionaries'))
############# I18n gem translation ######################################
diff --git a/gem/lib/pagy/i18n.rb b/gem/lib/pagy/i18n.rb
index 5b48e0572..99a129fe6 100644
--- a/gem/lib/pagy/i18n.rb
+++ b/gem/lib/pagy/i18n.rb
@@ -9,8 +9,8 @@ module I18n
extend self
# rubocop:disable Style/MutableConstant
- PATHNAMES = [ROOT.join('locales')]
- DATA = {}
+ LOOKUP_PATHNAMES = [ROOT.join('locales')]
+ DATA = {}
# rubocop:enable Style/MutableConstant
# Translate and pluralize the key with the locale DATA
@@ -24,7 +24,7 @@ def translate(key, locale:, **options)
private
def load(locale)
- path = PATHNAMES.map { |p| p.join("#{locale}.yml") }.find(&:exist?)
+ path = LOOKUP_PATHNAMES.map { |p| p.join("#{locale}.yml") }.find(&:exist?)
raise Errno::ENOENT, "missing dictionary file for #{locale.inspect} locale" unless path
dictionary = YAML.load_file(path)[locale]
@@ -33,8 +33,9 @@ def load(locale)
end
# Create a flat hash with dotted notation keys
+ # e.g. { 'a' => { 'b' => {'c' => 3, 'd' => 4 }}} -> { 'a.b.c' => 3, 'a.b.d' => 4 }
def flatten_to_dot_keys(initial, prefix = '')
- initial.each.reduce({}) do |hash, (key, value)|
+ initial.reduce({}) do |hash, (key, value)|
hash.merge!(value.is_a?(Hash) ? flatten_to_dot_keys(value, "#{prefix}#{key}.") : { "#{prefix}#{key}" => value })
end
end
diff --git a/test/pagy/backend/keynav_test.rb b/test/pagy/backend/keynav_test.rb
index d92accee5..eba61e24e 100644
--- a/test/pagy/backend/keynav_test.rb
+++ b/test/pagy/backend/keynav_test.rb
@@ -8,7 +8,7 @@
describe 'Keynav' do
[Pet, PetSequel].each do |model|
- describe 'pagy_augmented' do
+ describe "pagy_augmented #{model}" do
it 'works for page 1' do
app = MockApp.new(params: {})
pagy, records = app.send(:pagy_keynav_js,
diff --git a/test/pagy/backend/keyset_test.rb b/test/pagy/backend/keyset_test.rb
index 15a6e0457..bf6aec34f 100644
--- a/test/pagy/backend/keyset_test.rb
+++ b/test/pagy/backend/keyset_test.rb
@@ -6,7 +6,7 @@
describe 'keyset' do
[Pet, PetSequel].each do |model|
- describe '#pagy_keyset' do
+ describe "#pagy_keyset #{model}" do
it 'returns Pagy::Keyset object and records' do
app = MockApp.new(params: { page: nil })
pagy, records = app.send(:pagy_keyset,
@@ -27,7 +27,7 @@
_(pagy.next).must_equal "WzIwXQ"
end
end
- describe 'URL helpers' do
+ describe "URL helpers #{model}" do
it 'returns the URLs for first page' do
app = MockApp.new(params: { page: nil, limit: 10 })
pagy, _records = app.send(:pagy_keyset,
diff --git a/test/pagy/frontend/i18n_test.rb b/test/pagy/frontend/i18n_test.rb
index a1c0a424f..9fb5becdb 100644
--- a/test/pagy/frontend/i18n_test.rb
+++ b/test/pagy/frontend/i18n_test.rb
@@ -3,7 +3,7 @@
require_relative '../../test_helper'
require_relative '../../mock_helpers/app'
-describe 'pagy/legacy/i18n' do
+describe 'pagy/i18n' do
let(:app) { MockApp.new }
##### pagy.rb initializer ###############
diff --git a/test/pagy/frontend/i18n_test.rb.yaml b/test/pagy/frontend/i18n_test.rb.yaml
index cc89e1682..92d837e36 100644
--- a/test/pagy/frontend/i18n_test.rb.yaml
+++ b/test/pagy/frontend/i18n_test.rb.yaml
@@ -9,3 +9,8 @@ pagy/legacy/i18n___pagy_info_with_I18n_test_0001_renders_info:
:info_1: Displaying 1 item
:info_13: Displaying 13 items
:info_100: Displaying items 41-60 of 100 in total
+pagy/i18n___pagy_info_with_I18n_test_0001_renders_info:
+ :info_0: No items found
+ :info_1: Displaying 1 item
+ :info_13: Displaying 13 items
+ :info_100: Displaying items 41-60 of 100 in total
diff --git a/test/pagy/offset_test.rb b/test/pagy/offset_test.rb
index 2d47c2e18..04f788401 100644
--- a/test/pagy/offset_test.rb
+++ b/test/pagy/offset_test.rb
@@ -2,13 +2,13 @@
require_relative '../test_helper'
-describe 'pagy' do
+OPTIONS = { count: 103, limit: 10 }.freeze
+OPTS_WITH_LENGTH = [3, 6, 9].map { |l| OPTIONS.merge(length: l) }.freeze
+
+describe 'pagy offset' do
let(:pagy) { Pagy::Offset.new(count: 100, page: 4) }
- describe '#initialize' do
- before do
- @options = { count: 103, limit: 10 }
- end
+ describe 'initialize' do
it 'initializes' do
_(pagy).must_be_instance_of Pagy::Offset
_(Pagy::Offset.new(count: 100)).must_be_instance_of Pagy::Offset
@@ -29,8 +29,7 @@
end
end
it 'initializes count 0' do
- pagy = Pagy::Offset.new(**@options, count: 0)
- _(pagy.last).must_equal 1
+ pagy = Pagy::Offset.new(**OPTIONS, count: 0)
_(pagy.last).must_equal 1
_(pagy.offset).must_equal 0
_(pagy.in).must_equal 0
@@ -40,8 +39,7 @@
_(pagy.next).must_be_nil
end
it 'initializes single page' do
- pagy = Pagy::Offset.new(**@options, count: 8)
- _(pagy.last).must_equal 1
+ pagy = Pagy::Offset.new(**OPTIONS, count: 8)
_(pagy.last).must_equal 1
_(pagy.offset).must_equal 0
_(pagy.in).must_equal 8
@@ -51,8 +49,7 @@
_(pagy.next).must_be_nil
end
it 'initializes page 1 of 2' do
- pagy = Pagy::Offset.new(**@options, count: 15)
- _(pagy.last).must_equal 2
+ pagy = Pagy::Offset.new(**OPTIONS, count: 15)
_(pagy.last).must_equal 2
_(pagy.offset).must_equal 0
_(pagy.in).must_equal 10
@@ -62,8 +59,7 @@
_(pagy.next).must_equal 2
end
it 'initializes page 2 of 2' do
- pagy = Pagy::Offset.new(**@options, count: 15, page: 2)
- _(pagy.last).must_equal 2
+ pagy = Pagy::Offset.new(**OPTIONS, count: 15, page: 2)
_(pagy.last).must_equal 2
_(pagy.offset).must_equal 10
_(pagy.in).must_equal 5
@@ -74,10 +70,9 @@
_(pagy.next).must_be_nil
end
it 'initializes page 1' do
- pagy = Pagy::Offset.new(**@options, page: 1)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 1)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 0
_(pagy.in).must_equal 10
@@ -88,10 +83,9 @@
_(pagy.next).must_equal 2
end
it 'initializes page 2' do
- pagy = Pagy::Offset.new(**@options, page: 2)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 2)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 10
_(pagy.in).must_equal 10
@@ -102,10 +96,9 @@
_(pagy.next).must_equal 3
end
it 'initializes page 3' do
- pagy = Pagy::Offset.new(**@options, page: 3)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 3)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 20
_(pagy.in).must_equal 10
@@ -116,10 +109,9 @@
_(pagy.next).must_equal 4
end
it 'initializes page 4' do
- pagy = Pagy::Offset.new(**@options, page: 4)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 4)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 30
_(pagy.in).must_equal 10
@@ -130,10 +122,9 @@
_(pagy.next).must_equal 5
end
it 'initializes page 5' do
- pagy = Pagy::Offset.new(**@options, page: 5)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 5)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 40
_(pagy.in).must_equal 10
@@ -144,10 +135,9 @@
_(pagy.next).must_equal 6
end
it 'initializes page 6' do
- pagy = Pagy::Offset.new(**@options, page: 6)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 6)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 50
_(pagy.in).must_equal 10
@@ -158,10 +148,9 @@
_(pagy.next).must_equal 7
end
it 'initializes page 7' do
- pagy = Pagy::Offset.new(**@options, page: 7)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 7)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 60
_(pagy.in).must_equal 10
@@ -172,10 +161,9 @@
_(pagy.next).must_equal 8
end
it 'initializes page 8' do
- pagy = Pagy::Offset.new(**@options, page: 8)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 8)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 70
_(pagy.in).must_equal 10
@@ -186,10 +174,9 @@
_(pagy.next).must_equal 9
end
it 'initializes page 9' do
- pagy = Pagy::Offset.new(**@options, page: 9)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 9)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 80
_(pagy.in).must_equal 10
@@ -200,10 +187,9 @@
_(pagy.next).must_equal 10
end
it 'initializes page 10' do
- pagy = Pagy::Offset.new(**@options, page: 10)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 10)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 90
_(pagy.in).must_equal 10
@@ -214,10 +200,9 @@
_(pagy.next).must_equal 11
end
it 'initializes page 11' do
- pagy = Pagy::Offset.new(**@options, page: 11)
+ pagy = Pagy::Offset.new(**OPTIONS, page: 11)
_(pagy.count).must_equal 103
_(pagy.last).must_equal 11
- _(pagy.last).must_equal 11
_(pagy.limit).must_equal 10
_(pagy.offset).must_equal 100
_(pagy.in).must_equal 3
@@ -258,106 +243,72 @@
end
end
- describe '#series (length = Integer)' do
- before do
- @opts0 = { count: 103,
- limit: 10,
- length: 3 }
- @opts1 = { count: 103,
- limit: 10,
- length: 6 }
- @opts2 = { count: 103,
- limit: 10,
- length: 9 }
- end
-
- def series_for(page, *expected)
+ describe 'series' do
+ [[1,
+ ["1", 2, 3],
+ ["1", 2, 3, 4, 5, 6],
+ ["1", 2, 3, 4, 5, 6, 7, :gap, 11]],
+ [2,
+ [1, "2", 3],
+ [1, "2", 3, 4, 5, 6],
+ [1, "2", 3, 4, 5, 6, 7, :gap, 11]],
+ [3,
+ [2, "3", 4],
+ [1, 2, "3", 4, 5, 6],
+ [1, 2, "3", 4, 5, 6, 7, :gap, 11]],
+ [4,
+ [3, "4", 5],
+ [2, 3, "4", 5, 6, 7],
+ [1, 2, 3, "4", 5, 6, 7, :gap, 11]],
+ [5,
+ [4, "5", 6],
+ [3, 4, "5", 6, 7, 8],
+ [1, 2, 3, 4, "5", 6, 7, :gap, 11]],
+ [6,
+ [5, "6", 7],
+ [4, 5, "6", 7, 8, 9],
+ [1, :gap, 4, 5, "6", 7, 8, :gap, 11]],
+ [7,
+ [6, "7", 8],
+ [5, 6, "7", 8, 9, 10],
+ [1, :gap, 5, 6, "7", 8, 9, 10, 11]],
+ [8,
+ [7, "8", 9],
+ [6, 7, "8", 9, 10, 11],
+ [1, :gap, 5, 6, 7, "8", 9, 10, 11]],
+ [9,
+ [8, "9", 10],
+ [6, 7, 8, "9", 10, 11],
+ [1, :gap, 5, 6, 7, 8, "9", 10, 11]],
+ [10,
+ [9, "10", 11],
+ [6, 7, 8, 9, "10", 11],
+ [1, :gap, 5, 6, 7, 8, 9, "10", 11]],
+ [11,
+ [9, 10, "11"],
+ [6, 7, 8, 9, 10, "11"],
+ [1, :gap, 5, 6, 7, 8, 9, 10, "11"]]].each do |page, *expected|
expected.each_with_index do |value, index|
- options = instance_variable_get(:"@opts#{index}").merge(page: page)
- _(Pagy::Offset.new(**options).series).must_equal value
+ it "computes series for page #{page}, length #{OPTS_WITH_LENGTH[index][:length]}" do
+ _(Pagy::Offset.new(**OPTS_WITH_LENGTH[index], page:).series).must_equal value
+ end
end
end
- it 'computes series for page 1' do
- series_for 1,
- ["1", 2, 3],
- ["1", 2, 3, 4, 5, 6],
- ["1", 2, 3, 4, 5, 6, 7, :gap, 11]
- end
- it 'computes series for page 2' do
- series_for 2,
- [1, "2", 3],
- [1, "2", 3, 4, 5, 6],
- [1, "2", 3, 4, 5, 6, 7, :gap, 11]
- end
- it 'computes series for page 3' do
- series_for 3,
- [2, "3", 4],
- [1, 2, "3", 4, 5, 6],
- [1, 2, "3", 4, 5, 6, 7, :gap, 11]
- end
- it 'computes series for page 4' do
- series_for 4,
- [3, "4", 5],
- [2, 3, "4", 5, 6, 7],
- [1, 2, 3, "4", 5, 6, 7, :gap, 11]
- end
- it 'computes series for page 5' do
- series_for 5,
- [4, "5", 6],
- [3, 4, "5", 6, 7, 8],
- [1, 2, 3, 4, "5", 6, 7, :gap, 11]
- end
- it 'computes series for page 6' do
- series_for 6,
- [5, "6", 7],
- [4, 5, "6", 7, 8, 9],
- [1, :gap, 4, 5, "6", 7, 8, :gap, 11]
- end
- it 'computes series for page 7' do
- series_for 7,
- [6, "7", 8],
- [5, 6, "7", 8, 9, 10],
- [1, :gap, 5, 6, "7", 8, 9, 10, 11]
- end
- it 'computes series for page 8' do
- series_for 8,
- [7, "8", 9],
- [6, 7, "8", 9, 10, 11],
- [1, :gap, 5, 6, 7, "8", 9, 10, 11]
- end
- it 'computes series for page 9' do
- series_for 9,
- [8, "9", 10],
- [6, 7, 8, "9", 10, 11],
- [1, :gap, 5, 6, 7, 8, "9", 10, 11]
- end
- it 'computes series for page 10' do
- series_for 10,
- [9, "10", 11],
- [6, 7, 8, 9, "10", 11],
- [1, :gap, 5, 6, 7, 8, 9, "10", 11]
- end
- it 'computes series for page 11' do
- series_for 11,
- [9, 10, "11"],
- [6, 7, 8, 9, 10, "11"],
- [1, :gap, 5, 6, 7, 8, 9, 10, "11"]
- end
it 'computes series for count 0' do
- _(Pagy::Offset.new(**@opts2, count: 0).series).must_equal ["1"]
+ _(Pagy::Offset.new(**OPTS_WITH_LENGTH[2], count: 0).series).must_equal ["1"]
end
it 'computes series for single page' do
- _(Pagy::Offset.new(**@opts2, count: 8).series).must_equal ["1"]
+ _(Pagy::Offset.new(**OPTS_WITH_LENGTH[2], count: 8).series).must_equal ["1"]
end
it 'computes series for 1 of 2 pages' do
- _(Pagy::Offset.new(**@opts2, count: 15).series).must_equal ["1", 2]
+ _(Pagy::Offset.new(**OPTS_WITH_LENGTH[2], count: 15).series).must_equal ["1", 2]
end
it 'computes series for 2 of 2 pages' do
- _(Pagy::Offset.new(**@opts2, count: 15, page: 2).series).must_equal [1, "2"]
+ _(Pagy::Offset.new(**OPTS_WITH_LENGTH[2], count: 15, page: 2).series).must_equal [1, "2"]
end
it 'computes an empty series' do
- _(Pagy::Offset.new(**@opts2, count: 100, length: 0).series).must_equal []
+ _(Pagy::Offset.new(**OPTS_WITH_LENGTH[2], count: 100, length: 0).series).must_equal []
end
it 'raises OptionError for invalid length' do
_ { Pagy::Offset.new(count: 100, length: {}).series }.must_raise Pagy::OptionError