2013-10-24 11:16:14 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe 'Search::GlobalService', services: true do
|
2014-06-18 05:53:29 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:public_user) { create(:user) }
|
|
|
|
let(:internal_user) { create(:user) }
|
2013-10-24 11:16:14 -04:00
|
|
|
|
2014-06-18 05:53:29 -04:00
|
|
|
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') }
|
2014-01-09 07:23:07 -05:00
|
|
|
|
2014-06-18 05:53:29 -04:00
|
|
|
before do
|
|
|
|
found_project.team << [user, :master]
|
|
|
|
end
|
2013-10-24 11:16:14 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
2014-01-09 07:23:07 -05:00
|
|
|
context 'unauthenticated' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns public projects only' do
|
2014-01-16 13:29:18 -05:00
|
|
|
context = Search::GlobalService.new(nil, search: "searchable")
|
2014-01-09 07:23:07 -05:00
|
|
|
results = context.execute
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(results.objects('projects')).to match_array [public_project]
|
2014-01-09 07:23:07 -05:00
|
|
|
end
|
2013-10-24 11:16:14 -04:00
|
|
|
end
|
|
|
|
|
2014-01-09 07:23:07 -05:00
|
|
|
context 'authenticated' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns public, internal and private projects' do
|
2014-01-16 13:29:18 -05:00
|
|
|
context = Search::GlobalService.new(user, search: "searchable")
|
2014-01-09 07:23:07 -05:00
|
|
|
results = context.execute
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(results.objects('projects')).to match_array [public_project, found_project, internal_project]
|
2014-01-09 07:23:07 -05:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns only public & internal projects' do
|
2014-01-16 13:29:18 -05:00
|
|
|
context = Search::GlobalService.new(internal_user, search: "searchable")
|
2014-01-09 07:23:07 -05:00
|
|
|
results = context.execute
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(results.objects('projects')).to match_array [internal_project, public_project]
|
2014-01-09 07:23:07 -05:00
|
|
|
end
|
2013-11-06 10:13:21 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'namespace name is searchable' do
|
2014-06-18 05:53:29 -04:00
|
|
|
context = Search::GlobalService.new(user, search: found_project.namespace.path)
|
2014-01-09 07:23:07 -05:00
|
|
|
results = context.execute
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(results.objects('projects')).to match_array [found_project]
|
2014-01-09 07:23:07 -05:00
|
|
|
end
|
2013-10-24 11:16:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|