BigW Consortium Gitlab

project_search_results_spec.rb 3.53 KB
Newer Older
1 2
require 'spec_helper'

Douwe Maan committed
3
describe Gitlab::ProjectSearchResults, lib: true do
4
  let(:user) { create(:user) }
5 6 7 8
  let(:project) { create(:project) }
  let(:query) { 'hello world' }

  describe 'initialize with empty ref' do
9
    let(:results) { Gitlab::ProjectSearchResults.new(user, project, query, '') }
10 11 12

    it { expect(results.project).to eq(project) }
    it { expect(results.repository_ref).to be_nil }
13
    it { expect(results.query).to eq('hello world') }
14 15 16 17
  end

  describe 'initialize with ref' do
    let(:ref) { 'refs/heads/test' }
18
    let(:results) { Gitlab::ProjectSearchResults.new(user, project, query, ref) }
19 20 21

    it { expect(results.project).to eq(project) }
    it { expect(results.repository_ref).to eq(ref) }
22
    it { expect(results.query).to eq('hello world') }
23
  end
24 25 26 27 28 29 30 31 32 33 34 35

  describe 'confidential issues' do
    let(:query) { 'issue' }
    let(:author) { create(:user) }
    let(:assignee) { create(:user) }
    let(:non_member) { create(:user) }
    let(:member) { create(:user) }
    let(:admin) { create(:admin) }
    let!(:issue) { create(:issue, project: project, title: 'Issue 1') }
    let!(:security_issue_1) { create(:issue, :confidential, project: project, title: 'Security issue 1', author: author) }
    let!(:security_issue_2) { create(:issue, :confidential, title: 'Security issue 2', project: project, assignee: assignee) }

36
    it 'does not list project confidential issues for non project members' do
37 38 39 40 41 42 43 44 45
      results = described_class.new(non_member, project, query)
      issues = results.objects('issues')

      expect(issues).to include issue
      expect(issues).not_to include security_issue_1
      expect(issues).not_to include security_issue_2
      expect(results.issues_count).to eq 1
    end

46
    it 'does not list project confidential issues for project members with guest role' do
47 48 49 50 51 52 53 54 55 56 57
      project.team << [member, :guest]

      results = described_class.new(member, project, query)
      issues = results.objects('issues')

      expect(issues).to include issue
      expect(issues).not_to include security_issue_1
      expect(issues).not_to include security_issue_2
      expect(results.issues_count).to eq 1
    end

58
    it 'lists project confidential issues for author' do
59 60 61 62 63 64 65 66 67
      results = described_class.new(author, project, query)
      issues = results.objects('issues')

      expect(issues).to include issue
      expect(issues).to include security_issue_1
      expect(issues).not_to include security_issue_2
      expect(results.issues_count).to eq 2
    end

68
    it 'lists project confidential issues for assignee' do
69 70 71 72 73 74 75 76 77
      results = described_class.new(assignee, project.id, query)
      issues = results.objects('issues')

      expect(issues).to include issue
      expect(issues).not_to include security_issue_1
      expect(issues).to include security_issue_2
      expect(results.issues_count).to eq 2
    end

78
    it 'lists project confidential issues for project members' do
79 80 81 82 83 84 85 86 87 88 89
      project.team << [member, :developer]

      results = described_class.new(member, project, query)
      issues = results.objects('issues')

      expect(issues).to include issue
      expect(issues).to include security_issue_1
      expect(issues).to include security_issue_2
      expect(results.issues_count).to eq 3
    end

90
    it 'lists all project issues for admin' do
91 92 93 94 95 96 97 98 99
      results = described_class.new(admin, project, query)
      issues = results.objects('issues')

      expect(issues).to include issue
      expect(issues).to include security_issue_1
      expect(issues).to include security_issue_2
      expect(results.issues_count).to eq 3
    end
  end
100
end