2017-04-13 11:20:04 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Search::GroupService do
|
2017-04-13 11:20:04 -04:00
|
|
|
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-08-02 15:55:11 -04:00
|
|
|
let!(:outside_project) { create(:project, :public, name: "Outside #{term}") }
|
|
|
|
let!(:private_project) { create(:project, :private, namespace: nested_group, name: "Private #{term}" )}
|
|
|
|
let!(:other_project) { create(:project, :public, namespace: nested_group, name: term.reverse) }
|
2017-04-13 11:20:04 -04:00
|
|
|
|
|
|
|
# These projects should be found
|
2017-08-02 15:55:11 -04:00
|
|
|
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-04-13 11:20:04 -04:00
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
let(:results) { described_class.new(user, search_group, search: term).execute }
|
2017-04-13 11:20:04 -04:00
|
|
|
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
|
|
|
|
end
|