debian-mirror-gitlab/spec/services/search/group_service_spec.rb

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

88 lines
4.1 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Search::GroupService do
2017-08-17 22:00:37 +05:30
shared_examples_for 'group search' do
context 'finding projects by name' do
let(:user) { create(:user) }
let(:term) { "Project Name" }
let(:nested_group) { create(:group, :nested) }
# These projects shouldn't be found
2017-09-10 17:25:29 +05:30
let!(:outside_project) { create(:project, :public, name: "Outside #{term}") }
2022-08-27 11:52:29 +05:30
let!(:private_project) { create(:project, :private, namespace: nested_group, name: "Private #{term}" ) }
2017-09-10 17:25:29 +05:30
let!(:other_project) { create(:project, :public, namespace: nested_group, name: term.reverse) }
2017-08-17 22:00:37 +05:30
# These projects should be found
2017-09-10 17:25:29 +05:30
let!(:project1) { create(:project, :internal, namespace: nested_group, name: "Inner #{term} 1") }
let!(:project2) { create(:project, :internal, namespace: nested_group, name: "Inner #{term} 2") }
let!(:project3) { create(:project, :internal, namespace: nested_group.parent, name: "Outer #{term}") }
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
let(:results) { described_class.new(user, search_group, search: term).execute }
2020-01-01 13:55:28 +05:30
2017-08-17 22:00:37 +05:30
subject { results.objects('projects') }
context 'in parent group' do
let(:search_group) { nested_group.parent }
it { is_expected.to match_array([project1, project2, project3]) }
end
context 'in subgroup' do
let(:search_group) { nested_group }
it { is_expected.to match_array([project1, project2]) }
end
end
end
describe 'basic search' do
include_examples 'group search'
end
2021-01-03 14:25:43 +05:30
context 'issues' do
let(:scope) { 'issues' }
2021-03-11 19:13:27 +05:30
context 'sorting' do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :public, group: group) }
2021-01-03 14:25:43 +05:30
let!(:old_result) { create(:issue, project: project, title: 'sorted old', created_at: 1.month.ago) }
let!(:new_result) { create(:issue, project: project, title: 'sorted recent', created_at: 1.day.ago) }
let!(:very_old_result) { create(:issue, project: project, title: 'sorted very old', created_at: 1.year.ago) }
2021-03-11 19:13:27 +05:30
let!(:old_updated) { create(:issue, project: project, title: 'updated old', updated_at: 1.month.ago) }
let!(:new_updated) { create(:issue, project: project, title: 'updated recent', updated_at: 1.day.ago) }
let!(:very_old_updated) { create(:issue, project: project, title: 'updated very old', updated_at: 1.year.ago) }
2021-01-03 14:25:43 +05:30
include_examples 'search results sorted' do
2021-03-11 19:13:27 +05:30
let(:results_created) { described_class.new(nil, group, search: 'sorted', sort: sort).execute }
let(:results_updated) { described_class.new(nil, group, search: 'updated', sort: sort).execute }
2021-01-03 14:25:43 +05:30
end
end
end
context 'merge requests' do
let(:scope) { 'merge_requests' }
2021-03-11 19:13:27 +05:30
context 'sorting' do
2021-01-03 14:25:43 +05:30
let!(:group) { create(:group) }
let!(:project) { create(:project, :public, group: group) }
2021-03-11 19:13:27 +05:30
2021-01-03 14:25:43 +05:30
let!(:old_result) { create(:merge_request, :opened, source_project: project, source_branch: 'old-1', title: 'sorted old', created_at: 1.month.ago) }
let!(:new_result) { create(:merge_request, :opened, source_project: project, source_branch: 'new-1', title: 'sorted recent', created_at: 1.day.ago) }
let!(:very_old_result) { create(:merge_request, :opened, source_project: project, source_branch: 'very-old-1', title: 'sorted very old', created_at: 1.year.ago) }
2021-03-11 19:13:27 +05:30
let!(:old_updated) { create(:merge_request, :opened, source_project: project, source_branch: 'updated-old-1', title: 'updated old', updated_at: 1.month.ago) }
let!(:new_updated) { create(:merge_request, :opened, source_project: project, source_branch: 'updated-new-1', title: 'updated recent', updated_at: 1.day.ago) }
let!(:very_old_updated) { create(:merge_request, :opened, source_project: project, source_branch: 'updated-very-old-1', title: 'updated very old', updated_at: 1.year.ago) }
2021-01-03 14:25:43 +05:30
include_examples 'search results sorted' do
2021-03-11 19:13:27 +05:30
let(:results_created) { described_class.new(nil, group, search: 'sorted', sort: sort).execute }
let(:results_updated) { described_class.new(nil, group, search: 'updated', sort: sort).execute }
2021-01-03 14:25:43 +05:30
end
end
end
2017-08-17 22:00:37 +05:30
end