2013-10-24 11:16:14 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-01-16 13:29:18 -05:00
|
|
|
describe 'Search::GlobalService' do
|
2013-10-24 11:16:14 -04:00
|
|
|
let(:found_namespace) { create(:namespace, name: 'searchable namespace', path:'another_thing') }
|
|
|
|
let(:user) { create(:user, namespace: found_namespace) }
|
2013-11-06 10:13:21 -05:00
|
|
|
let!(:found_project) { create(:project, name: 'searchable_project', creator_id: user.id, namespace: found_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) }
|
2013-10-24 11:16:14 -04:00
|
|
|
|
|
|
|
let(:unfound_namespace) { create(:namespace, name: 'unfound namespace', path: 'yet_something_else') }
|
2013-11-06 10:13:21 -05:00
|
|
|
let!(:unfound_project) { create(:project, name: 'unfound_project', creator_id: user.id, namespace: unfound_namespace, visibility_level: Gitlab::VisibilityLevel::PRIVATE) }
|
2014-01-09 07:23:07 -05:00
|
|
|
|
2013-11-06 10:13:21 -05:00
|
|
|
let(:internal_namespace) { create(:namespace, path: 'something_internal',name: 'searchable internal namespace') }
|
|
|
|
let(:internal_user) { create(:user, namespace: internal_namespace) }
|
|
|
|
let!(:internal_project) { create(:project, name: 'searchable_internal_project', creator_id: internal_user.id, namespace: internal_namespace, visibility_level: Gitlab::VisibilityLevel::INTERNAL) }
|
2014-01-09 07:23:07 -05:00
|
|
|
|
2013-11-06 10:13:21 -05:00
|
|
|
let(:public_namespace) { create(:namespace, path: 'something_public',name: 'searchable public namespace') }
|
|
|
|
let(:public_user) { create(:user, namespace: public_namespace) }
|
|
|
|
let!(:public_project) { create(:project, name: 'searchable_public_project', creator_id: public_user.id, namespace: public_namespace, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
|
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
|
|
|
|
results[:projects].should have(1).items
|
|
|
|
results[:projects].should include(public_project)
|
|
|
|
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
|
|
|
|
results[:projects].should have(3).items
|
|
|
|
results[:projects].should include(public_project)
|
|
|
|
results[:projects].should include(found_project)
|
|
|
|
results[:projects].should include(internal_project)
|
|
|
|
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
|
|
|
|
results[:projects].should have(2).items
|
|
|
|
results[:projects].should include(internal_project)
|
|
|
|
results[:projects].should include(public_project)
|
|
|
|
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-01-16 13:29:18 -05:00
|
|
|
context = Search::GlobalService.new(user, search: "searchable namespace")
|
2014-01-09 07:23:07 -05:00
|
|
|
results = context.execute
|
|
|
|
results[:projects].should == [found_project]
|
|
|
|
end
|
2013-10-24 11:16:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|