BigW Consortium Gitlab

projects_finder_spec.rb 2.49 KB
Newer Older
1 2
require 'spec_helper'

3
describe ProjectsFinder do
4 5
  describe '#execute' do
    let(:user) { create(:user) }
Douwe Maan committed
6
    let(:group) { create(:group, :public) }
7

8 9 10 11 12 13 14 15 16 17 18
    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
19

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

24
    let(:finder) { described_class.new }
25

26 27 28
    describe 'without a group' do
      describe 'without a user' do
        subject { finder.execute }
29

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

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

36 37 38
        describe 'without private projects' do
          it { is_expected.to eq([public_project, internal_project]) }
        end
39

40 41 42 43
        describe 'with private projects' do
          before do
            private_project.team.add_user(user, Gitlab::Access::MASTER)
          end
44

45 46 47 48 49 50 51 52 53 54 55
          it do
            is_expected.to eq([public_project, internal_project,
                               private_project])
          end
        end
      end
    end

    describe 'with a group' do
      describe 'without a user' do
        subject { finder.execute(nil, group: group) }
56

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

60 61
      describe 'with a user' do
        subject { finder.execute(user, group: group) }
62

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
        describe 'without shared projects' do
          it { is_expected.to eq([public_project, internal_project]) }
        end

        describe 'with shared projects and group membership' do
          before do
            group.add_user(user, Gitlab::Access::DEVELOPER)

            shared_project.project_group_links.
              create(group_access: Gitlab::Access::MASTER, group: group)
          end

          it do
            is_expected.to eq([shared_project, public_project, internal_project])
          end
        end

        describe 'with shared projects and project membership' do
          before do
            shared_project.team.add_user(user, Gitlab::Access::DEVELOPER)

            shared_project.project_group_links.
              create(group_access: Gitlab::Access::MASTER, group: group)
          end

          it do
            is_expected.to eq([shared_project, public_project, internal_project])
          end
        end
92 93
      end
    end
94 95
  end
end