Skip to content

Commit

Permalink
changed the argument order from pagy_url_for(page, pagy) > pagy_url_f…
Browse files Browse the repository at this point in the history
…or(pagy, page) for consistency with all the other helpers; deprecation warning and support for pagy < 5
  • Loading branch information
ddnexus committed Apr 23, 2021
1 parent 393d216 commit 64347f8
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 64 deletions.
3 changes: 2 additions & 1 deletion lib/pagy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def series(size=@vars[:size])
series[series.index(@page)] = @page.to_s
series
end

end

require 'pagy/deprecation'
require 'pagy/backend'
require 'pagy/frontend'
require 'pagy/exceptions'
20 changes: 20 additions & 0 deletions lib/pagy/deprecation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true
class Pagy
class << self

# deprecated pagy_url_for rgument order
def deprecated_order(pagy, page)
Warning.warn '[PAGY WARNING] inverted use of pagy/page in pagy_url_for will not be supported in 5.0! Use pagy_url_for(pagy, page) instead.'
[page, pagy]
end


# deprecated arguments to remove in 5.0
def deprecated_arg(arg, val, new_key, new_val)
value = new_val || val # we use the new_val if present
Warning.warn %([PAGY WARNING] deprecated use of positional `#{arg}` arg will not be supported in 5.0! Use only the keyword arg `#{new_key}: #{value.inspect}` instead.)
value
end

end
end
4 changes: 2 additions & 2 deletions lib/pagy/extras/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def pagy_bootstrap_nav(pagy, pagy_id: nil, link_extra: '')

# Javascript pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_bootstrap_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, %(class="page-link" #{link_extra}))
tags = { 'before' => %(<ul class="pagination">#{pagy_bootstrap_prev_html pagy, link}),
Expand All @@ -41,7 +41,7 @@ def pagy_bootstrap_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '',

# Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_bootstrap_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/bulma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '')
end

def pagy_bulma_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
tags = { 'before' => %(#{pagy_bulma_prev_next_html(pagy, link)}<ul class="pagination-list">),
Expand All @@ -40,7 +40,7 @@ def pagy_bulma_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', ste

# Javascript combo pagination for Bulma: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_bulma_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/foundation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def pagy_foundation_nav(pagy, pagy_id: nil, link_extra: '')

# Javascript pagination for foundation: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_foundation_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
tags = { 'before' => %(<ul class="pagination">#{pagy_foundation_prev_html pagy, link}),
Expand All @@ -41,7 +41,7 @@ def pagy_foundation_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: ''

# Javascript combo pagination for Foundation: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_foundation_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def pagy_headers_hash(pagy)
countless = defined?(Pagy::Countless) && pagy.is_a?(Pagy::Countless)
rels = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }
rels['last'] = pagy.last unless countless
url_str = pagy_url_for(PAGE_PLACEHOLDER, pagy, :url)
url_str = pagy_url_for(pagy, PAGE_PLACEHOLDER, :url)
hash = { 'Link' => rels.filter_map do |rel, num|
next unless num
[ rel, url_str.sub(PAGE_PLACEHOLDER, num.to_s) ]
Expand Down
5 changes: 3 additions & 2 deletions lib/pagy/extras/items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module Frontend

module UseItemsExtra

def pagy_url_for(page, pagy, url=nil)
def pagy_url_for(pagy, page, url=nil)
pagy, page = Pagy.deprecated_order(pagy, page) if page.is_a?(Pagy)
p_vars = pagy.vars
params = request.GET.merge(p_vars[:params])
params[p_vars[:page_param].to_s] = page
Expand All @@ -50,7 +51,7 @@ def pagy_url_for(page, pagy, url=nil)

# Return the items selector HTML. For example "Show [20] items per page"
def pagy_items_selector_js(pagy, deprecated_id=nil, pagy_id: nil, item_name: nil, i18n_key: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
p_vars = pagy.vars
p_items = p_vars[:items]
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/materialize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def pagy_materialize_nav(pagy, pagy_id: nil, link_extra: '')

# Javascript pagination for materialize: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_materialize_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)

Expand All @@ -42,7 +42,7 @@ def pagy_materialize_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '

# Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_materialize_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def pagy_metadata(pagy, url=nil)
raise VariableError.new(pagy), "unknown metadata #{unknown.inspect}" \
unless unknown.empty?

scaffold_url = pagy_url_for(PAGE_PLACEHOLDER, pagy, url)
scaffold_url = pagy_url_for(pagy, PAGE_PLACEHOLDER, url)
{}.tap do |metadata|
names.each do |key|
metadata[key] = case key
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/navs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Frontend

# Javascript pagination: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
tags = { 'before' => pagy_nav_prev_html(pagy, link),
Expand All @@ -23,7 +23,7 @@ def pagy_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: ni

# Javascript combo pagination: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/semantic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def pagy_semantic_nav(pagy, pagy_id: nil, link_extra: '')

# Javascript pagination for semantic: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_semantic_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, %(class="item" #{link_extra}))
tags = { 'before' => pagy_semantic_prev_html(pagy, link),
Expand All @@ -41,7 +41,7 @@ def pagy_semantic_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '',

# Combo pagination for semantic: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_semantic_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, %(class="item" #{link_extra}))
p_page = pagy.page
Expand Down
20 changes: 10 additions & 10 deletions lib/pagy/extras/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ class Pagy
module Frontend

def pagy_prev_url(pagy)
pagy_url_for(pagy.prev, pagy) if pagy.prev
pagy_url_for(pagy, pagy.prev) if pagy.prev
end

def pagy_next_url(pagy)
pagy_url_for(pagy.next, pagy) if pagy.next
pagy_url_for(pagy, pagy.next) if pagy.next
end

def pagy_prev_link(pagy, deprecated_text=nil, deprecated_link_extra=nil, text: pagy_t('pagy.nav.prev'), link_extra: '')
text = pagy_deprecated_arg(:text, deprecated_text, :text, text) if deprecated_text
link_extra = pagy_deprecated_arg(:link_extra, deprecated_link_extra, :link_extra, link_extra) if deprecated_link_extra
text = Pagy.deprecated_arg(:text, deprecated_text, :text, text) if deprecated_text
link_extra = Pagy.deprecated_arg(:link_extra, deprecated_link_extra, :link_extra, link_extra) if deprecated_link_extra
if pagy.prev
%(<span class="page prev"><a href="#{pagy_url_for(pagy.prev, pagy)}" rel="prev" aria-label="previous" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
%(<span class="page prev"><a href="#{pagy_url_for(pagy, pagy.prev)}" rel="prev" aria-label="previous" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
else
%(<span class="page prev disabled">#{text}</span>)
end
end

def pagy_next_link(pagy, deprecated_text=nil, deprecated_link_extra=nil, text: pagy_t('pagy.nav.next'), link_extra: '')
text = pagy_deprecated_arg(:text, deprecated_text, :text, text) if deprecated_text
link_extra = pagy_deprecated_arg(:link_extra, deprecated_link_extra, :link_extra, link_extra) if deprecated_link_extra
text = Pagy.deprecated_arg(:text, deprecated_text, :text, text) if deprecated_text
link_extra = Pagy.deprecated_arg(:link_extra, deprecated_link_extra, :link_extra, link_extra) if deprecated_link_extra
if pagy.next
%(<span class="page next"><a href="#{pagy_url_for(pagy.next, pagy)}" rel="next" aria-label="next" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
%(<span class="page next"><a href="#{pagy_url_for(pagy, pagy.next)}" rel="next" aria-label="next" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
else
%(<span class="page next disabled">#{text}</span>)
end
end

def pagy_prev_link_tag(pagy)
%(<link href="#{pagy_url_for(pagy.prev, pagy)}" rel="prev"/>) if pagy.prev
%(<link href="#{pagy_url_for(pagy, pagy.prev)}" rel="prev"/>) if pagy.prev
end

def pagy_next_link_tag(pagy)
%(<link href="#{pagy_url_for(pagy.next, pagy)}" rel="next"/>) if pagy.next
%(<link href="#{pagy_url_for(pagy, pagy.next)}" rel="next"/>) if pagy.next
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/uikit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def pagy_uikit_nav(pagy, pagy_id: nil, link_extra: '')

# Javascript pagination for uikit: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_uikit_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
tags = { 'before' => pagy_uikit_prev_html(pagy, link),
Expand All @@ -40,7 +40,7 @@ def pagy_uikit_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', ste

# Javascript combo pagination for uikit: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_uikit_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
Expand Down
14 changes: 4 additions & 10 deletions lib/pagy/frontend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Pagy

module Helpers
# This works with all Rack-based frameworks (Sinatra, Padrino, Rails, ...)
def pagy_url_for(page, pagy, url=nil)
def pagy_url_for(pagy, page, url=nil)
pagy, page = Pagy.deprecated_order(pagy, page) if page.is_a?(Pagy)
p_vars = pagy.vars
params = request.GET.merge(p_vars[:params])
params[p_vars[:page_param].to_s] = page
Expand Down Expand Up @@ -60,7 +61,7 @@ def pagy_nav(pagy, pagy_id: nil, link_extra: '')

# Return examples: "Displaying items 41-60 of 324 in total" of "Displaying Products 41-60 of 324 in total"
def pagy_info(pagy, deprecated_item_name=nil, item_name: nil, i18n_key: nil)
item_name = pagy_deprecated_arg(:item_name, deprecated_item_name, :item_name, item_name) if deprecated_item_name
item_name = Pagy.deprecated_arg(:item_name, deprecated_item_name, :item_name, item_name) if deprecated_item_name
p_count = pagy.count
key = if p_count.zero? then 'pagy.info.no_items'
elsif pagy.pages == 1 then 'pagy.info.single_page'
Expand All @@ -75,7 +76,7 @@ def pagy_info(pagy, deprecated_item_name=nil, item_name: nil, i18n_key: nil)
def pagy_link_proc(pagy, link_extra='')
p_prev = pagy.prev
p_next = pagy.next
left, right = %(<a href="#{pagy_url_for PAGE_PLACEHOLDER, pagy}" #{pagy.vars[:link_extra]} #{link_extra}).split(PAGE_PLACEHOLDER, 2)
left, right = %(<a href="#{pagy_url_for pagy, PAGE_PLACEHOLDER}" #{pagy.vars[:link_extra]} #{link_extra}).split(PAGE_PLACEHOLDER, 2)
lambda do |num, text=num, extra_attrs=''|
%(#{left}#{num}#{right}#{ case num
when p_prev then ' rel="prev"'
Expand All @@ -91,12 +92,5 @@ def pagy_t(key, **opts)
Pagy::I18n.t @pagy_locale||=nil, key, **opts
end

# deprecated arguments to remove in 5.0
def pagy_deprecated_arg(arg, val, new_key, new_val)
value = new_val || val # we use the new_val if present
Warning.warn %([PAGY WARNING] deprecated positional `#{arg}` arg, it will be removed in 5.0! Use only the keyword arg `#{new_key}: #{value.inspect}` instead.\n)
value
end

end
end
1 change: 1 addition & 0 deletions pagy.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ lib/locales/zh-TW.yml
lib/pagy.rb
lib/pagy/backend.rb
lib/pagy/countless.rb
lib/pagy/deprecation.rb
lib/pagy/exceptions.rb
lib/pagy/extras/arel.rb
lib/pagy/extras/array.rb
Expand Down
20 changes: 20 additions & 0 deletions test/pagy/derecation_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require_relative '../test_helper'

describe 'pagy/deprecation' do

describe 'Pagy.deprecated_arg' do
it 'deprecate arg and returns right value' do
_ { _(Pagy.deprecated_arg(:arg, 'deprecated-val', :new_key, 'new-value')).must_equal 'new-value' }.must_output nil, \
"[PAGY WARNING] deprecated use of positional `arg` arg will not be supported in 5.0! Use only the keyword arg `new_key: \"new-value\"` instead."
end
end

describe 'Pagy.deprecated_order' do
it 'deprecate arg order and returns them inverted' do
_ { _(Pagy.deprecated_order('page', 'pagy')).must_equal %w[pagy page] }.must_output nil, \
"[PAGY WARNING] inverted use of pagy/page in pagy_url_for will not be supported in 5.0! Use pagy_url_for(pagy, page) instead."
end
end
end
10 changes: 5 additions & 5 deletions test/pagy/extras/items_countless_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,23 @@
describe '#pagy_url_for' do
it 'renders basic url' do
pagy = Pagy.new count: 1000, page: 3
_(view.pagy_url_for(5, pagy)).must_equal '/foo?page=5&items=20'
_(view.pagy_url_for(pagy, 5)).must_equal '/foo?page=5&items=20'
end
it 'renders basic url and items var' do
pagy = Pagy.new count: 1000, page: 3, items: 50
_(view.pagy_url_for(5, pagy)).must_equal '/foo?page=5&items=50'
_(view.pagy_url_for(pagy, 5)).must_equal '/foo?page=5&items=50'
end
it 'renders url with items_params' do
pagy = Pagy.new count: 1000, page: 3, items_param: :custom
_(view.pagy_url_for(5, pagy)).must_equal '/foo?page=5&custom=20'
_(view.pagy_url_for(pagy, 5)).must_equal '/foo?page=5&custom=20'
end
it 'renders url with anchor' do
pagy = Pagy.new count: 1000, page: 3, anchor: '#anchor'
_(view.pagy_url_for(6, pagy)).must_equal '/foo?page=6&items=20#anchor'
_(view.pagy_url_for(pagy, 6)).must_equal '/foo?page=6&items=20#anchor'
end
it 'renders url with params and anchor' do
pagy = Pagy.new count: 1000, page: 3, params: {a: 3, b: 4}, anchor: '#anchor', items: 40
_(view.pagy_url_for(5, pagy)).must_equal "/foo?page=5&a=3&b=4&items=40#anchor"
_(view.pagy_url_for(pagy, 5)).must_equal "/foo?page=5&a=3&b=4&items=40#anchor"
end
end
it 'renders items selector with countless' do
Expand Down
10 changes: 5 additions & 5 deletions test/pagy/extras/items_elasticsearch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,23 @@
describe '#pagy_url_for' do
it 'renders basic url' do
pagy = Pagy.new count: 1000, page: 3
_(view.pagy_url_for(5, pagy)).must_equal '/foo?page=5&items=20'
_(view.pagy_url_for(pagy, 5)).must_equal '/foo?page=5&items=20'
end
it 'renders basic url and items var' do
pagy = Pagy.new count: 1000, page: 3, items: 50
_(view.pagy_url_for(5, pagy)).must_equal '/foo?page=5&items=50'
_(view.pagy_url_for(pagy, 5)).must_equal '/foo?page=5&items=50'
end
it 'renders url with items_params' do
pagy = Pagy.new count: 1000, page: 3, items_param: :custom
_(view.pagy_url_for(5, pagy)).must_equal '/foo?page=5&custom=20'
_(view.pagy_url_for(pagy, 5)).must_equal '/foo?page=5&custom=20'
end
it 'renders url with anchor' do
pagy = Pagy.new count: 1000, page: 3, anchor: '#anchor'
_(view.pagy_url_for(6, pagy)).must_equal '/foo?page=6&items=20#anchor'
_(view.pagy_url_for(pagy, 6)).must_equal '/foo?page=6&items=20#anchor'
end
it 'renders url with params and anchor' do
pagy = Pagy.new count: 1000, page: 3, params: {a: 3, b: 4}, anchor: '#anchor', items: 40
_(view.pagy_url_for(5, pagy)).must_equal "/foo?page=5&a=3&b=4&items=40#anchor"
_(view.pagy_url_for(pagy, 5)).must_equal "/foo?page=5&a=3&b=4&items=40#anchor"
end
end
it 'renders items selector with elasticsearch' do
Expand Down
Loading

0 comments on commit 64347f8

Please sign in to comment.