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
path: root/spec
diff options
context:
space:
mode:
authorMarin Jankovski <marin@gitlab.com>2019-10-02 12:09:24 +0300
committerMarin Jankovski <marin@gitlab.com>2019-10-02 12:09:24 +0300
commitf7e0be9bbe1173b0de18a52a21b49d19349f40b7 (patch)
treeab16636b3b537cd0546a705afb707508f4caa6b4 /spec
parent95793b2325f6a9add2395d89447bd0e64b870cd1 (diff)
parent32a97baefbfae943da2248ac0097ae801b142e5a (diff)
Merge branch 'master' of dev.gitlab.org:gitlab/gitlabhq
Diffstat (limited to 'spec')
-rw-r--r--spec/support/helpers/search_results_helpers.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/support/helpers/search_results_helpers.rb b/spec/support/helpers/search_results_helpers.rb
new file mode 100644
index 00000000000..f626a85877b
--- /dev/null
+++ b/spec/support/helpers/search_results_helpers.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module SearchResultHelpers
+ # @param target [Symbol] search target, e.g. "merge_requests", "blobs"
+ def expect_search_results(users, target, expected_count: nil, expected_objects: nil)
+ # TODO: https://gitlab.com/gitlab-org/gitlab/issues/32645
+ return if expected_count && expected_count > 0
+
+ users = Array(users)
+ target = target.to_s
+
+ users.each do |user|
+ user_name = user&.name || 'anonymous user'
+ results = yield(user)
+ objects = results.objects(target)
+
+ if expected_count
+ actual_count = results.public_send("#{target}_count")
+
+ expect(actual_count).to eq(expected_count), "expected count to be #{expected_count} for #{user_name}, got #{actual_count}"
+ end
+
+ if expected_objects
+ if expected_objects.empty?
+ expect(objects.empty?).to eq(true)
+ else
+ expect(objects).to contain_exactly(*expected_objects)
+ end
+ end
+ end
+ end
+end