2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe 'Search::GlobalService', services: true do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:public_user) { create(:user) }
|
|
|
|
let(:internal_user) { create(:user) }
|
|
|
|
|
|
|
|
let!(:found_project) { create(:empty_project, :private, name: 'searchable_project') }
|
|
|
|
let!(:unfound_project) { create(:empty_project, :private, name: 'unfound_project') }
|
|
|
|
let!(:internal_project) { create(:empty_project, :internal, name: 'searchable_internal_project') }
|
|
|
|
let!(:public_project) { create(:empty_project, :public, name: 'searchable_public_project') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
found_project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'unauthenticated' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns public projects only' do
|
2014-09-02 18:07:02 +05:30
|
|
|
context = Search::GlobalService.new(nil, search: "searchable")
|
|
|
|
results = context.execute
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(results.objects('projects')).to match_array [public_project]
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'authenticated' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns public, internal and private projects' do
|
2014-09-02 18:07:02 +05:30
|
|
|
context = Search::GlobalService.new(user, search: "searchable")
|
|
|
|
results = context.execute
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(results.objects('projects')).to match_array [public_project, found_project, internal_project]
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns only public & internal projects' do
|
2014-09-02 18:07:02 +05:30
|
|
|
context = Search::GlobalService.new(internal_user, search: "searchable")
|
|
|
|
results = context.execute
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(results.objects('projects')).to match_array [internal_project, public_project]
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'namespace name is searchable' do
|
2014-09-02 18:07:02 +05:30
|
|
|
context = Search::GlobalService.new(user, search: found_project.namespace.path)
|
|
|
|
results = context.execute
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(results.objects('projects')).to match_array [found_project]
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|