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

56 lines
1.9 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'
2017-09-10 17:25:29 +05:30
describe Search::GlobalService do
2017-08-17 22:00:37 +05:30
let(:user) { create(:user) }
let(:internal_user) { create(:user) }
2017-09-10 17:25:29 +05:30
let!(:found_project) { create(:project, :private, name: 'searchable_project') }
let!(:unfound_project) { create(:project, :private, name: 'unfound_project') }
let!(:internal_project) { create(:project, :internal, name: 'searchable_internal_project') }
let!(:public_project) { create(:project, :public, name: 'searchable_public_project') }
2017-08-17 22:00:37 +05:30
before do
2018-11-18 11:00:15 +05:30
found_project.add_maintainer(user)
2017-08-17 22:00:37 +05:30
end
describe '#execute' do
context 'unauthenticated' do
it 'returns public projects only' do
2017-09-10 17:25:29 +05:30
results = described_class.new(nil, search: "searchable").execute
2017-08-17 22:00:37 +05:30
expect(results.objects('projects')).to match_array [public_project]
end
end
context 'authenticated' do
it 'returns public, internal and private projects' do
2017-09-10 17:25:29 +05:30
results = described_class.new(user, search: "searchable").execute
2017-08-17 22:00:37 +05:30
expect(results.objects('projects')).to match_array [public_project, found_project, internal_project]
end
it 'returns only public & internal projects' do
2017-09-10 17:25:29 +05:30
results = described_class.new(internal_user, search: "searchable").execute
2017-08-17 22:00:37 +05:30
expect(results.objects('projects')).to match_array [internal_project, public_project]
end
2018-03-17 18:26:18 +05:30
it 'project name is searchable' do
results = described_class.new(user, search: found_project.name).execute
2017-08-17 22:00:37 +05:30
expect(results.objects('projects')).to match_array [found_project]
end
2019-12-04 20:38:33 +05:30
it 'does not return archived projects' do
archived_project = create(:project, :public, archived: true, name: 'archived_project')
results = described_class.new(user, search: "archived").execute
expect(results.objects('projects')).not_to include(archived_project)
end
2017-08-17 22:00:37 +05:30
end
end
end