Commit 9b2ca8da authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch '324970-add-sort-to-epics' into 'master'

Search: Add ability to sort Epic results

See merge request gitlab-org/gitlab!64402
parents 82d85407 df6a2a94
......@@ -16,7 +16,7 @@ class SearchServicePresenter < Gitlab::View::Presenter::Delegated
blobs: :with_web_entity_associations
}.freeze
SORT_ENABLED_SCOPES = %w(issues merge_requests).freeze
SORT_ENABLED_SCOPES = %w(issues merge_requests epics).freeze
def search_objects
@search_objects ||= begin
......
......@@ -5,9 +5,10 @@ module EE
module GroupSearchResults
extend ::Gitlab::Utils::Override
override :epics
def epics
EpicsFinder.new(current_user, issuable_params).execute.search(query)
epics = EpicsFinder.new(current_user, issuable_params).execute.search(query)
apply_sort(epics)
end
end
end
......
......@@ -15,12 +15,6 @@ module EE
end
end
def epics
groups_finder = GroupsFinder.new(current_user)
::Epic.in_selected_groups(groups_finder.execute).search(query)
end
private
override :projects
......
......@@ -8,20 +8,40 @@ RSpec.describe Gitlab::GroupSearchResults do
subject { described_class.new(user, query, group: group) }
before do
create(:group_member, group: group, user: user)
group.add_owner(user)
stub_licensed_features(epics: true)
end
describe '#epics' do
let(:query) { 'foo' }
let!(:searchable_epic) { create(:epic, title: 'foo', group: group) }
let!(:another_searchable_epic) { create(:epic, title: 'foo 2', group: group) }
let!(:another_epic) { create(:epic) }
before do
create(:group_member, group: group, user: user)
group.add_owner(user)
stub_licensed_features(epics: true)
context 'searching' do
let(:query) { 'foo' }
let!(:searchable_epic) { create(:epic, title: 'foo', group: group) }
let!(:another_searchable_epic) { create(:epic, title: 'foo 2', group: group) }
let!(:another_epic) { create(:epic) }
it 'finds epics' do
expect(subject.objects('epics')).to match_array([searchable_epic, another_searchable_epic])
end
end
it 'finds epics' do
expect(subject.objects('epics')).to match_array([searchable_epic, another_searchable_epic])
context 'ordering' do
let(:scope) { 'epics' }
let(:filters) { {} }
let!(:old_result) { create(:epic, group: group, title: 'sorted old', created_at: 1.month.ago) }
let!(:new_result) { create(:epic, group: group, title: 'sorted recent', created_at: 1.day.ago) }
let!(:very_old_result) { create(:epic, group: group, title: 'sorted very old', created_at: 1.year.ago) }
let!(:old_updated) { create(:epic, group: group, title: 'updated old', updated_at: 1.month.ago) }
let!(:new_updated) { create(:epic, group: group, title: 'updated recent', updated_at: 1.day.ago) }
let!(:very_old_updated) { create(:epic, group: group, title: 'updated very old', updated_at: 1.year.ago) }
include_examples 'search results sorted' do
let(:results_created) { described_class.new(user, 'sorted', Project.order(:id), group: group, sort: sort, filters: filters) }
let(:results_updated) { described_class.new(user, 'updated', Project.order(:id), group: group, sort: sort, filters: filters) }
end
end
end
end
......@@ -24,22 +24,6 @@ RSpec.describe Gitlab::SearchResults do
end
end
describe '#epics' do
let!(:group) { create(:group, :private) }
let!(:searchable_epic) { create(:epic, title: 'foo', group: group) }
let!(:another_group) { create(:group, :private) }
let!(:another_epic) { create(:epic, title: 'foo 2', group: another_group) }
before do
create(:group_member, group: group, user: user)
group.add_owner(user)
end
it 'finds epics' do
expect(subject.objects('epics')).to match_array([searchable_epic])
end
end
def search
subject.objects('projects').map { |project| project.compliance_framework_setting.framework }
end
......
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