From 24d977fc515aba78371a70c6bcc514b462b66e92 Mon Sep 17 00:00:00 2001
From: Domizio Demichelis
Date: Thu, 2 Jan 2025 16:51:54 +0700
Subject: [PATCH] Update Gemfile, test and code for rubocop and psych
---
.github/workflows/ruby-test.yml | 2 +-
.rubocop.yml | 2 +-
Gemfile | 3 +++
Gemfile.lock | 8 +++++++-
gem/lib/pagy/calendar.rb | 2 +-
gem/lib/pagy/extras/calendar.rb | 4 ++--
gem/lib/pagy/extras/i18n.rb | 4 ++--
gem/lib/pagy/extras/jsonapi.rb | 14 +++++++-------
gem/lib/pagy/frontend.rb | 4 ++--
gem/lib/pagy/url_helpers.rb | 2 ++
gem/pagy.gemspec | 2 +-
test/mock_helpers/elasticsearch_rails.rb | 12 ++++++------
test/mock_helpers/meilisearch.rb | 4 ++--
test/pagy/extras/calendar_extra_test.rb | 4 ++--
test/pagy/extras/standalone_test.rb | 10 ----------
test/pagy/url_helpers_test.rb | 10 ++++++++++
16 files changed, 49 insertions(+), 38 deletions(-)
diff --git a/.github/workflows/ruby-test.yml b/.github/workflows/ruby-test.yml
index 06db11768..f8e01d336 100644
--- a/.github/workflows/ruby-test.yml
+++ b/.github/workflows/ruby-test.yml
@@ -16,7 +16,7 @@ jobs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
- uses: fkirc/skip-duplicate-actions@v5.3.1
+ uses: fkirc/skip-duplicate-actions@master
with:
concurrent_skipping: 'never'
skip_after_successful_duplicate: 'true'
diff --git a/.rubocop.yml b/.rubocop.yml
index 5e829674d..096492273 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -6,7 +6,7 @@ require:
# trying to be good O:)
AllCops:
- TargetRubyVersion: 3.1
+ TargetRubyVersion: 3.2
NewCops: enable
Exclude:
- ___*/**/*
diff --git a/Gemfile b/Gemfile
index 478f369b4..7ce55ea0d 100644
--- a/Gemfile
+++ b/Gemfile
@@ -5,7 +5,10 @@ source 'https://rubygems.org'
gemspec path: './gem'
gem 'http' # used by the scripts/contributor-list.rb
+gem 'irb'
gem 'rake'
+gem 'reline'
+gem 'uri'
group :test do
gem 'activesupport'
diff --git a/Gemfile.lock b/Gemfile.lock
index 4e9395840..9e98c7651 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -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
@@ -247,7 +248,9 @@ GEM
regexp_parser (2.10.0)
reline (0.6.0)
io-console (~> 0.5)
- rematch (3.1.0)
+ rematch (3.2.0)
+ logger
+ pstore
rerun (0.14.0)
listen (~> 3.0)
rouge (4.5.1)
@@ -337,6 +340,7 @@ DEPENDENCIES
groupdate
http
i18n
+ irb
minitest
minitest-reporters
mutex_m
@@ -347,6 +351,7 @@ DEPENDENCIES
rackup
rails (~> 8.0)
rake
+ reline
rematch
rerun
rouge
@@ -359,6 +364,7 @@ DEPENDENCIES
simplecov
sinatra
sqlite3
+ uri
BUNDLED WITH
2.6.2
diff --git a/gem/lib/pagy/calendar.rb b/gem/lib/pagy/calendar.rb
index 1c123b9b9..dbedd698f 100644
--- a/gem/lib/pagy/calendar.rb
+++ b/gem/lib/pagy/calendar.rb
@@ -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
diff --git a/gem/lib/pagy/extras/calendar.rb b/gem/lib/pagy/extras/calendar.rb
index 9353459a9..60858b7fc 100644
--- a/gem/lib/pagy/extras/calendar.rb
+++ b/gem/lib/pagy/extras/calendar.rb
@@ -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
diff --git a/gem/lib/pagy/extras/i18n.rb b/gem/lib/pagy/extras/i18n.rb
index 26a37c2dc..dd81b10e3 100644
--- a/gem/lib/pagy/extras/i18n.rb
+++ b/gem/lib/pagy/extras/i18n.rb
@@ -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
diff --git a/gem/lib/pagy/extras/jsonapi.rb b/gem/lib/pagy/extras/jsonapi.rb
index 0a767f490..6c39f8d9a 100644
--- a/gem/lib/pagy/extras/jsonapi.rb
+++ b/gem/lib/pagy/extras/jsonapi.rb
@@ -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
diff --git a/gem/lib/pagy/frontend.rb b/gem/lib/pagy/frontend.rb
index 7f4ac71d3..acdc5d184 100644
--- a/gem/lib/pagy/frontend.rb
+++ b/gem/lib/pagy/frontend.rb
@@ -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
diff --git a/gem/lib/pagy/url_helpers.rb b/gem/lib/pagy/url_helpers.rb
index df779b22f..6d25ed874 100644
--- a/gem/lib/pagy/url_helpers.rb
+++ b/gem/lib/pagy/url_helpers.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require 'uri'
+
class Pagy
# Provide the helpers to handle the url in frontend and backend
module UrlHelpers
diff --git a/gem/pagy.gemspec b/gem/pagy.gemspec
index e7040d35d..6fa02ac4b 100644
--- a/gem/pagy.gemspec
+++ b/gem/pagy.gemspec
@@ -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
diff --git a/test/mock_helpers/elasticsearch_rails.rb b/test/mock_helpers/elasticsearch_rails.rb
index 95d2e56bb..1f4e3f9e6 100644
--- a/test/mock_helpers/elasticsearch_rails.rb
+++ b/test/mock_helpers/elasticsearch_rails.rb
@@ -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
@@ -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
@@ -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
diff --git a/test/mock_helpers/meilisearch.rb b/test/mock_helpers/meilisearch.rb
index a13637256..28429db00 100644
--- a/test/mock_helpers/meilisearch.rb
+++ b/test/mock_helpers/meilisearch.rb
@@ -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
diff --git a/test/pagy/extras/calendar_extra_test.rb b/test/pagy/extras/calendar_extra_test.rb
index 623c38752..6cc5f6b69 100644
--- a/test/pagy/extras/calendar_extra_test.rb
+++ b/test/pagy/extras/calendar_extra_test.rb
@@ -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
diff --git a/test/pagy/extras/standalone_test.rb b/test/pagy/extras/standalone_test.rb
index 5b59d2b41..7f59ccba2 100644
--- a/test/pagy/extras/standalone_test.rb
+++ b/test/pagy/extras/standalone_test.rb
@@ -87,13 +87,3 @@ def params
end
end
end
-
-describe 'pagy/extras/standalone/query_utils' do
- it 'handles nested hashes' do
- _(Pagy::UrlHelpers::QueryUtils.build_nested_query({ a: { b: 2 } })).must_equal "a%5Bb%5D=2" # "a[b]=2"
- _(Pagy::UrlHelpers::QueryUtils.build_nested_query({ a: { b: { c: 3 } } })).must_equal "a%5Bb%5D%5Bc%5D=3" # "a[b][c]=3"
- end
- it 'raises ArgumentError for wrong params' do
- _ { Pagy::UrlHelpers::QueryUtils.build_nested_query('just a string') }.must_raise ArgumentError
- end
-end
diff --git a/test/pagy/url_helpers_test.rb b/test/pagy/url_helpers_test.rb
index 11197695d..cd320d1bd 100644
--- a/test/pagy/url_helpers_test.rb
+++ b/test/pagy/url_helpers_test.rb
@@ -45,4 +45,14 @@
_(app.pagy_url_for(pagy, 5, fragment: '#fragment')).must_equal "/foo?a=5&page=5&b=4&add_me=add_me#fragment"
end
end
+
+ describe 'pagy/extras/standalone/query_utils' do
+ it 'handles nested hashes' do
+ _(Pagy::UrlHelpers::QueryUtils.build_nested_query({ a: { b: 2 } })).must_equal "a%5Bb%5D=2" # "a[b]=2"
+ _(Pagy::UrlHelpers::QueryUtils.build_nested_query({ a: { b: { c: 3 } } })).must_equal "a%5Bb%5D%5Bc%5D=3" # "a[b][c]=3"
+ end
+ it 'raises ArgumentError for wrong params' do
+ _ { Pagy::UrlHelpers::QueryUtils.build_nested_query('just a string') }.must_raise ArgumentError
+ end
+ end
end