2017-03-31 13:03:55 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Search::GlobalService do
|
2017-03-31 13:03:55 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:internal_user) { create(:user) }
|
|
|
|
|
2017-08-02 19:55:11 +00:00
|
|
|
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-03-31 13:03:55 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
found_project.add_master(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'unauthenticated' do
|
|
|
|
it 'returns public projects only' do
|
2017-07-25 17:09:00 +00:00
|
|
|
results = described_class.new(nil, search: "searchable").execute
|
2017-03-31 13:03:55 +00:00
|
|
|
|
|
|
|
expect(results.objects('projects')).to match_array [public_project]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'authenticated' do
|
|
|
|
it 'returns public, internal and private projects' do
|
2017-07-25 17:09:00 +00:00
|
|
|
results = described_class.new(user, search: "searchable").execute
|
2017-03-31 13:03:55 +00:00
|
|
|
|
|
|
|
expect(results.objects('projects')).to match_array [public_project, found_project, internal_project]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns only public & internal projects' do
|
2017-07-25 17:09:00 +00:00
|
|
|
results = described_class.new(internal_user, search: "searchable").execute
|
2017-03-31 13:03:55 +00:00
|
|
|
|
|
|
|
expect(results.objects('projects')).to match_array [internal_project, public_project]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'namespace name is searchable' do
|
2017-07-25 17:09:00 +00:00
|
|
|
results = described_class.new(user, search: found_project.namespace.path).execute
|
2017-03-31 13:03:55 +00:00
|
|
|
|
|
|
|
expect(results.objects('projects')).to match_array [found_project]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|