Welcome to mirror list, hosted at ThFree Co, Russian Federation.

search_service_spec.rb « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b467282a5d66217349cf6805cd77cbbfddf2556d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'spec_helper'

describe 'Search::GlobalService' do
  let(:user) { create(:user, namespace: found_namespace) }
  let(:public_user) { create(:user, namespace: public_namespace) }
  let(:internal_user) { create(:user, namespace: internal_namespace) }

  let(:found_namespace) { create(:namespace, name: 'searchable namespace', path:'another_thing') }
  let(:unfound_namespace) { create(:namespace, name: 'unfound namespace', path: 'yet_something_else') }
  let(:internal_namespace) { create(:namespace, name: 'searchable internal namespace', path: 'something_internal') }
  let(:public_namespace) { create(:namespace, name: 'searchable public namespace', path: 'something_public') }

  let!(:found_project) { create(:project, :private, name: 'searchable_project', creator_id: user.id, namespace: found_namespace) }
  let!(:unfound_project) { create(:project, :private, name: 'unfound_project', creator_id: user.id, namespace: unfound_namespace) }
  let!(:internal_project) { create(:project, :internal, name: 'searchable_internal_project', creator_id: internal_user.id, namespace: internal_namespace) }
  let!(:public_project) { create(:project, :public, name: 'searchable_public_project', creator_id: public_user.id, namespace: public_namespace) }

  describe '#execute' do
    context 'unauthenticated' do
      it 'should return public projects only' do
        context = Search::GlobalService.new(nil, search: "searchable")
        results = context.execute
        results[:projects].should match_array [public_project]
      end
    end

    context 'authenticated' do
      it 'should return public, internal and private projects' do
        context = Search::GlobalService.new(user, search: "searchable")
        results = context.execute
        results[:projects].should match_array [public_project, found_project, internal_project]
      end

      it 'should return only public & internal projects' do
        context = Search::GlobalService.new(internal_user, search: "searchable")
        results = context.execute
        results[:projects].should match_array [internal_project, public_project]
      end

      it 'namespace name should be searchable' do
        context = Search::GlobalService.new(user, search: "searchable namespace")
        results = context.execute
        results[:projects].should match_array [found_project]
      end
    end
  end
end