summaryrefslogtreecommitdiff
path: root/spec/finders/projects_finder_spec.rb
blob: 26a13d4046a6c6925ff46c277b3e720e247ec17e (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'spec_helper'

describe ProjectsFinder do
  describe '#execute' do
    let(:user) { create(:user) }
    let(:group) { create(:group, :public) }

    let!(:private_project) do
      create(:project, :private, name: 'A', path: 'A')
    end

    let!(:internal_project) do
      create(:project, :internal, group: group, name: 'B', path: 'B')
    end

    let!(:public_project) do
      create(:project, :public, group: group, name: 'C', path: 'C')
    end

    let!(:shared_project) do
      create(:project, :private, name: 'D', path: 'D')
    end

    let(:finder) { described_class.new }

    describe 'without a user' do
      subject { finder.execute }

      it { is_expected.to eq([public_project]) }
    end

    describe 'with a user' do
      subject { finder.execute(user) }

      describe 'without private projects' do
        it { is_expected.to include(public_project) }
        it { is_expected.to include(internal_project) }
        it { expect(subject.count).to eq(2) }
      end

      describe 'with private projects' do
        before do
          private_project.add_user(user, Gitlab::Access::MASTER)
        end

        it do
          it { is_expected.to include(public_project) }
          it { is_expected.to include(internal_project) }
          it { is_expected.to include(private_project) }
          it { expect(subject.count).to eq(3) }
        end
      end
    end

    describe 'with project_ids_relation' do
      let(:project_ids_relation) { Project.where(id: internal_project.id) }

      subject { finder.execute(user, project_ids_relation) }

      it { is_expected.to eq([internal_project]) }
    end
  end
end