Commit b3133798 authored by Dmytro Zaporozhets's avatar Dmytro Zaporozhets

Merge branch 'cl-wiki-result' into 'master'

Wrap wiki blob search result in its own object

See merge request gitlab-org/gitlab!31155
parents 6a5a9690 fcab4df1
---
title: Wrap wiki blob search result in its own object
merge_request: 31155
author:
type: fixed
......@@ -18,7 +18,7 @@ module Gitlab
when 'blobs'
paginated_blobs(blobs(limit: limit_up_to_page(page, per_page)), page, per_page)
when 'wiki_blobs'
paginated_blobs(wiki_blobs(limit: limit_up_to_page(page, per_page)), page, per_page)
paginated_wiki_blobs(wiki_blobs(limit: limit_up_to_page(page, per_page)), page, per_page)
when 'commits'
Kaminari.paginate_array(commits).page(page).per(per_page)
when 'users'
......@@ -94,6 +94,13 @@ module Gitlab
results
end
def paginated_wiki_blobs(blobs, page, per_page)
blob_array = paginated_blobs(blobs, page, per_page)
blob_array.map! do |blob|
Gitlab::Search::FoundWikiPage.new(blob)
end
end
def limit_up_to_page(page, per_page)
current_page = page&.to_i || 1
offset = per_page * (current_page - 1)
......
......@@ -225,6 +225,22 @@ describe Gitlab::ProjectSearchResults do
end
it_behaves_like 'blob search pagination', 'wiki_blobs'
context 'return type' do
let(:blobs) { [Gitlab::Search::FoundBlob.new(project: project)] }
let(:results) { described_class.new(user, project, "Files", per_page: 20) }
before do
allow(results).to receive(:wiki_blobs).and_return(blobs)
end
it 'returns list of FoundWikiPage type object' do
objects = results.objects('wiki_blobs')
expect(objects).to be_present
expect(objects).to all(be_a(Gitlab::Search::FoundWikiPage))
end
end
end
it 'does not list issues on private projects' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment