debian-mirror-gitlab/spec/support/helpers/keyset_pagination_helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
600 B
Ruby
Raw Normal View History

2023-06-20 00:43:36 +05:30
# frozen_string_literal: true
module KeysetPaginationHelpers
def pagination_links(response)
link = response.headers['LINK']
return unless link
link.split(',').filter_map do |link|
match = link.match(/<(?<url>.*)>; rel="(?<rel>\w+)"/)
2023-07-09 08:55:56 +05:30
next unless match
2023-06-20 00:43:36 +05:30
{ url: match[:url], rel: match[:rel] }
end
end
def pagination_params_from_next_url(response)
2023-07-09 08:55:56 +05:30
next_link = pagination_links(response).find { |link| link[:rel] == 'next' }
next_url = next_link&.fetch(:url)
return unless next_url
2023-06-20 00:43:36 +05:30
Rack::Utils.parse_query(URI.parse(next_url).query)
end
end