Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers/keyset_pagination_helpers.rb')
-rw-r--r--spec/support/helpers/keyset_pagination_helpers.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/support/helpers/keyset_pagination_helpers.rb b/spec/support/helpers/keyset_pagination_helpers.rb
new file mode 100644
index 00000000000..4bc20098e8c
--- /dev/null
+++ b/spec/support/helpers/keyset_pagination_helpers.rb
@@ -0,0 +1,20 @@
+# 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+)"/)
+ break nil unless match
+
+ { url: match[:url], rel: match[:rel] }
+ end
+ end
+
+ def pagination_params_from_next_url(response)
+ next_url = pagination_links(response).find { |link| link[:rel] == 'next' }[:url]
+ Rack::Utils.parse_query(URI.parse(next_url).query)
+ end
+end