From 8c21069cf8da96ea274db630437498762ebe6013 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Sat, 27 Jul 2024 09:37:35 +0700 Subject: [PATCH] Fix jsonapi with keyset --- gem/lib/pagy/extras/jsonapi.rb | 9 +++------ test/pagy/extras/jsonapi_test.rb.yaml | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/gem/lib/pagy/extras/jsonapi.rb b/gem/lib/pagy/extras/jsonapi.rb index 418753110..5dd07e9fb 100644 --- a/gem/lib/pagy/extras/jsonapi.rb +++ b/gem/lib/pagy/extras/jsonapi.rb @@ -47,7 +47,7 @@ def pagy_skip_jsonapi?(vars) # Override the Backend method def pagy_get_page(vars) return super if pagy_skip_jsonapi?(vars) - return if params[:page].nil? + return unless params[:page] params[:page][vars[:page_param] || DEFAULT[:page_param]] end @@ -61,7 +61,7 @@ module LimitExtraOverride # Override the LimitExtra::Backend method def pagy_get_limit_param(vars) return super if pagy_skip_jsonapi?(vars) - return if params[:page].nil? + return unless params[:page] params[:page][vars[:limit_param] || DEFAULT[:limit_param]] end @@ -77,11 +77,8 @@ def pagy_set_query_params(page, vars, query_params) return super unless vars[:jsonapi] query_params['page'] ||= {} - query_params['page'][vars[:page_param].to_s] = page if page + query_params['page'][vars[:page_param].to_s] = page query_params['page'][vars[:limit_param].to_s] = vars[:limit] if vars[:limit_extra] - # :nocov: - query_params.delete(:page) if query_params['page'].empty? - # :nocov: end end UrlHelpers.prepend UrlHelperOverride diff --git a/test/pagy/extras/jsonapi_test.rb.yaml b/test/pagy/extras/jsonapi_test.rb.yaml index 421e14942..5ada83907 100644 --- a/test/pagy/extras/jsonapi_test.rb.yaml +++ b/test/pagy/extras/jsonapi_test.rb.yaml @@ -1,13 +1,13 @@ --- pagy/extras/jsonapi___pagy_jsonapi_links_(keyset)_test_0002_sets_the_next_value_to_null_when_the_link_is_unavailable: :keyset_result: - :first: "/foo?page%5Bsize%5D=50" + :first: "/foo?page%5Bsize%5D=50&page%5Blatest%5D" :last: :prev: :next: pagy/extras/jsonapi___pagy_jsonapi_links_(keyset)_test_0001_returns_the_ordered_links: :keyset_result: - :first: "/foo?page%5Blatest%5D=eyJpZCI6MTB9&page%5Bsize%5D=10" + :first: "/foo?page%5Blatest%5D&page%5Bsize%5D=10" :last: :prev: :next: "/foo?page%5Blatest%5D=eyJpZCI6MjB9&page%5Bsize%5D=10"