Skip to content

Commit

Permalink
Update test and code for rubocop and psych
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jan 2, 2025
1 parent 3da8656 commit 2cb5f8c
Show file tree
Hide file tree
Showing 17 changed files with 868 additions and 879 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require:

# trying to be good O:)
AllCops:
TargetRubyVersion: 3.1
TargetRubyVersion: 3.2
NewCops: enable
Exclude:
- ___*/**/*
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ group :test do
gem 'minitest-reporters'
gem 'mutex_m'
gem 'oj', require: false # false is for testing with or without it
gem 'pstore' # waiting for the rematch update
gem 'rack'
gem 'rematch'
gem 'rubocop'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ GEM
parser (3.3.6.0)
ast (~> 2.4.1)
racc
pstore (0.1.4)
psych (5.2.2)
date
stringio
Expand Down Expand Up @@ -342,6 +343,7 @@ DEPENDENCIES
mutex_m
oj
pagy!
pstore
puma
rack
rackup
Expand Down
2 changes: 1 addition & 1 deletion gem/lib/pagy/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class << self
def create(unit, **vars)
raise InternalError, "unit must be in #{UNITS.inspect}; got #{unit}" unless UNITS.include?(unit)

name = unit.to_s
name = +unit.to_s
name[0] = name[0].capitalize
Object.const_get("Pagy::Calendar::#{name}").new(**vars)
end
Expand Down
4 changes: 2 additions & 2 deletions gem/lib/pagy/extras/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def pagy_anchor(pagy, anchor_string: nil)
# Additions for the Frontend module
module UrlHelperAddOn
# Return the url for the calendar page at time
def pagy_calendar_url_at(calendar, time, **opts)
pagy_url_for(calendar.send(:calendar_at, time, **opts), 1, **opts)
def pagy_calendar_url_at(calendar, time, **)
pagy_url_for(calendar.send(:calendar_at, time, **), 1, **)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions gem/lib/pagy/extras/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class Pagy # :nodoc:
module I18nExtra
# Frontend overriding for translation
module FrontendOverride
def pagy_t(key, **opts)
::I18n.t(key, **opts)
def pagy_t(key, **)
::I18n.t(key, **)
end
end
Frontend.prepend I18nExtra::FrontendOverride
Expand Down
14 changes: 7 additions & 7 deletions gem/lib/pagy/extras/jsonapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ module BackendOverride
include UrlHelpers

# Return the jsonapi links
def pagy_jsonapi_links(pagy, **opts)
def pagy_jsonapi_links(pagy, **)
if defined?(::Pagy::Keyset) && pagy.is_a?(Keyset)
{ first: pagy_url_for(pagy, nil, **opts),
{ first: pagy_url_for(pagy, nil, **),
last: nil,
prev: nil,
next: pagy.next ? pagy_url_for(pagy, pagy.next, **opts) : nil }
next: pagy.next ? pagy_url_for(pagy, pagy.next, **) : nil }
else
{ first: pagy_url_for(pagy, 1, **opts),
last: pagy_url_for(pagy, pagy.last, **opts),
prev: pagy.prev ? pagy_url_for(pagy, pagy.prev, **opts) : nil,
next: pagy.next ? pagy_url_for(pagy, pagy.next, **opts) : nil }
{ first: pagy_url_for(pagy, 1, **),
last: pagy_url_for(pagy, pagy.last, **),
prev: pagy.prev ? pagy_url_for(pagy, pagy.prev, **) : nil,
next: pagy.next ? pagy_url_for(pagy, pagy.next, **) : nil }
end
end

Expand Down
4 changes: 2 additions & 2 deletions gem/lib/pagy/frontend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def pagy_nav(pagy, id: nil, aria_label: nil, **vars)

# Similar to I18n.t: just ~18x faster using ~10x less memory
# (@pagy_locale explicitly initialized in order to avoid warning)
def pagy_t(key, **opts)
Pagy::I18n.translate(@pagy_locale ||= nil, key, **opts)
def pagy_t(key, **)
Pagy::I18n.translate(@pagy_locale ||= nil, key, **)
end

private
Expand Down
2 changes: 1 addition & 1 deletion gem/pagy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Gem::Specification.new do |s|
'changelog_uri' => 'https://github.com/ddnexus/pagy/blob/master/CHANGELOG.md',
'support' => 'https://github.com/ddnexus/pagy/discussions/categories/q-a' }
s.executables << 'pagy'
s.required_ruby_version = '>= 3.1'
s.required_ruby_version = '>= 3.2'
end
12 changes: 6 additions & 6 deletions test/mock_helpers/elasticsearch_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def records
end

class Model
def self.search(*args)
Response.new(*args)
def self.search(*)
Response.new(*)
end

extend Pagy::ElasticsearchRails
Expand All @@ -49,8 +49,8 @@ def initialize(query, options = {})
end

class ModelES7 < Model
def self.search(*args)
ResponseES7.new(*args)
def self.search(*)
ResponseES7.new(*)
end
end

Expand All @@ -73,8 +73,8 @@ def initialize(query, options = {})
end

class ModelES5 < Model
def self.search(*args)
ResponseES5.new(*args)
def self.search(*)
ResponseES5.new(*)
end
end
end
4 changes: 2 additions & 2 deletions test/mock_helpers/meilisearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def raw_answer
end

class Model
def self.ms_search(*args)
Results.new(*args)
def self.ms_search(*)
Results.new(*)
end

extend Pagy::Meilisearch
Expand Down
38 changes: 20 additions & 18 deletions test/pagy/extras/calendar_extra_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
Time.zone = 'GMT'
Date.beginning_of_week = :sunday

def app(**opts)
MockApp::Calendar.new(**opts)
def app(**)
MockApp::Calendar.new(**)
end

describe 'pagy/extras/calendar' do
Expand Down Expand Up @@ -59,7 +59,7 @@ def app(**opts)
_(calendar[:year].pages).must_equal 3
_(calendar[:year].prev).must_be_nil
_(calendar[:year].next).must_equal 2
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
total += entries.size
calendar, _pagy, entries = app(params: { year_page: 2 })
.send(:pagy_calendar,
Expand All @@ -70,7 +70,7 @@ def app(**opts)
_(calendar[:year].pages).must_equal 3
_(calendar[:year].prev).must_equal 1
_(calendar[:year].next).must_equal 3
_(entries.map(&:time)).must_rematch :entries_2
_(entries.map { |x| x.time.to_s }).must_rematch :entries_2
total += entries.size
calendar, _pagy, entries = app(params: { year_page: 3 })
.send(:pagy_calendar,
Expand All @@ -80,7 +80,7 @@ def app(**opts)
_(calendar[:year].series).must_equal [1, 2, '3']
_(calendar[:year].prev).must_equal 2
_(calendar[:year].next).must_be_nil
_(entries.map(&:time)).must_rematch :entries_3
_(entries.map { |x| x.time.to_s }).must_rematch :entries_3
total += entries.size
_(total).must_equal Event.all.size
end
Expand All @@ -94,7 +94,7 @@ def app(**opts)
_(calendar[:quarter].pages).must_equal 9
_(calendar[:quarter].prev).must_be_nil
_(calendar[:quarter].next).must_equal 2
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
it 'selects :quarter for an intermediate page' do
calendar, _pagy, entries = app(params: { quarter_page: 4 })
Expand All @@ -106,7 +106,7 @@ def app(**opts)
_(calendar[:quarter].pages).must_equal 9
_(calendar[:quarter].prev).must_equal 3
_(calendar[:quarter].next).must_equal 5
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
it 'selects :quarter for last page' do
calendar, _pagy, entries = app(params: { quarter_page: 9 })
Expand All @@ -118,7 +118,7 @@ def app(**opts)
_(calendar[:quarter].pages).must_equal 9
_(calendar[:quarter].prev).must_equal 8
_(calendar[:quarter].next).must_be_nil
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
it 'selects :month for the first page' do
calendar, _pagy, entries = app(params: { month_page: 1 })
Expand All @@ -130,7 +130,7 @@ def app(**opts)
_(calendar[:month].pages).must_equal 26
_(calendar[:month].prev).must_be_nil
_(calendar[:month].next).must_equal 2
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
it 'selects :month for an intermediate page' do
calendar, _pagy, entries = app(params: { month_page: 25 })
Expand All @@ -141,7 +141,7 @@ def app(**opts)
_(calendar[:month].series).must_equal [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, "25", 26]
_(calendar[:month].prev).must_equal 24
_(calendar[:month].next).must_equal 26
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
it 'selects :month for the last page' do
calendar, _pagy, entries = app(params: { month_page: 26 })
Expand All @@ -152,7 +152,7 @@ def app(**opts)
_(calendar[:month].series).must_equal [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, "26"]
_(calendar[:month].prev).must_equal 25
_(calendar[:month].next).must_be_nil
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
it 'selects :week for the first page' do
calendar, _pagy, entries = app(params: { week_page: 1 })
Expand All @@ -164,7 +164,7 @@ def app(**opts)
_(calendar[:week].pages).must_equal 109
_(calendar[:week].prev).must_be_nil
_(calendar[:week].next).must_equal 2
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
it 'selects :week for an intermediate page' do
calendar, _pagy, entries = app(params: { week_page: 25 })
Expand All @@ -175,7 +175,7 @@ def app(**opts)
_(calendar[:week].series).must_equal [1, :gap, 24, "25", 26, :gap, 109]
_(calendar[:week].prev).must_equal 24
_(calendar[:week].next).must_equal 26
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
it 'selects :week for the last page' do
calendar, _pagy, entries = app(params: { week_page: 109 })
Expand All @@ -186,7 +186,7 @@ def app(**opts)
_(calendar[:week].series).must_equal [1, :gap, 105, 106, 107, 108, "109"]
_(calendar[:week].prev).must_equal 108
_(calendar[:week].next).must_be_nil
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
it 'selects :day for the first page' do
calendar, _pagy, entries = app(params: { day_page: 1 })
Expand All @@ -199,7 +199,7 @@ def app(**opts)
_(calendar[:day].pages).must_equal 60
_(calendar[:day].prev).must_be_nil
_(calendar[:day].next).must_equal 2
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
it 'selects :day for an intermediate page' do
calendar, _pagy, entries = app(params: { day_page: 25 })
Expand All @@ -211,8 +211,9 @@ def app(**opts)

_(calendar[:day].prev).must_equal 24
_(calendar[:day].next).must_equal 26
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end

it 'selects :day for the last page' do
calendar, _pagy, entries = app(params: { day_page: 60 })
.send(:pagy_calendar,
Expand All @@ -222,8 +223,9 @@ def app(**opts)
_(calendar[:day].series).must_equal [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, "60"]
_(calendar[:day].prev).must_equal 59
_(calendar[:day].next).must_be_nil
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end

it 'runs multiple units' do
calendar, pagy, entries = app(params: { year_page: 2, month_page: 7, page: 2 })
.send(:pagy_calendar,
Expand All @@ -233,7 +235,7 @@ def app(**opts)
_(calendar[:year].series).must_equal [1, "2", 3]
_(calendar[:month].series).must_equal [1, 2, 3, 4, 5, 6, "7", 8, 9, 10, 11, 12]
_(pagy.series).must_equal [1, "2", 3]
_(entries.map(&:time)).must_rematch :entries
_(entries.map { |x| x.time.to_s }).must_rematch :entries
end
end

Expand Down
Loading

0 comments on commit 2cb5f8c

Please sign in to comment.