2013-10-24 11:16:14 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-01-16 13:29:18 -05:00
|
|
|
describe 'Search::GlobalService' 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
|
|
|
|
it 'should return 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
|
2014-08-27 08:26:35 -04:00
|
|
|
results.objects('projects').should 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
|
|
|
|
it 'should return 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
|
2014-08-27 08:26:35 -04:00
|
|
|
results.objects('projects').should match_array [public_project, found_project, internal_project]
|
2014-01-09 07:23:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return 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
|
2014-08-27 08:26:35 -04:00
|
|
|
results.objects('projects').should match_array [internal_project, public_project]
|
2014-01-09 07:23:07 -05:00
|
|
|
end
|
2013-11-06 10:13:21 -05:00
|
|
|
|
2014-01-09 07:23:07 -05:00
|
|
|
it 'namespace name should be 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
|
2014-08-27 08:26:35 -04:00
|
|
|
results.objects('projects').should match_array [found_project]
|
2014-01-09 07:23:07 -05:00
|
|
|
end
|
2013-10-24 11:16:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|