BigW Consortium Gitlab

group_projects_finder_spec.rb 3.13 KB
Newer Older
1 2 3 4 5
require 'spec_helper'

describe GroupProjectsFinder do
  let(:group) { create(:group) }
  let(:current_user) { create(:user) }
6
  let(:options) { {} }
7

8
  let(:finder) { described_class.new(group: group, current_user: current_user, options: options) }
9

10 11 12 13 14
  let!(:public_project) { create(:empty_project, :public, group: group, path: '1') }
  let!(:private_project) { create(:empty_project, :private, group: group, path: '2') }
  let!(:shared_project_1) { create(:empty_project, :public, path: '3') }
  let!(:shared_project_2) { create(:empty_project, :private, path: '4') }
  let!(:shared_project_3) { create(:empty_project, :internal, path: '5') }
15 16 17 18 19 20 21

  before do
    shared_project_1.project_group_links.create(group_access: Gitlab::Access::MASTER, group: group)
    shared_project_2.project_group_links.create(group_access: Gitlab::Access::MASTER, group: group)
    shared_project_3.project_group_links.create(group_access: Gitlab::Access::MASTER, group: group)
  end

22 23
  subject { finder.execute }

24
  describe 'with a group member current user' do
25 26 27
    before do
      group.add_master(current_user)
    end
28 29

    context "only shared" do
30 31 32
      let(:options) { { only_shared: true } }

      it { is_expected.to match_array([shared_project_3, shared_project_2, shared_project_1]) }
33 34 35
    end

    context "only owned" do
36 37 38
      let(:options) { { only_owned: true } }

      it { is_expected.to match_array([private_project, public_project]) }
39 40 41
    end

    context "all" do
42
      it { is_expected.to match_array([shared_project_3, shared_project_2, shared_project_1, private_project, public_project]) }
43 44 45 46
    end
  end

  describe 'without group member current_user' do
47 48 49 50
    before do
      shared_project_2.team << [current_user, Gitlab::Access::MASTER]
      current_user.reload
    end
51 52

    context "only shared" do
53 54
      let(:options) { { only_shared: true } }

55
      context "without external user" do
56
        it { is_expected.to match_array([shared_project_3, shared_project_2, shared_project_1]) }
57 58 59
      end

      context "with external user" do
60 61 62 63 64
        before do
          current_user.update_attributes(external: true)
        end

        it { is_expected.to match_array([shared_project_2, shared_project_1]) }
65 66 67 68
      end
    end

    context "only owned" do
69 70
      let(:options) { { only_owned: true } }

71
      context "without external user" do
72 73 74 75 76
        before do
          private_project.team << [current_user, Gitlab::Access::MASTER]
        end

        it { is_expected.to match_array([private_project, public_project]) }
77 78 79
      end

      context "with external user" do
80 81 82
        before do
          current_user.update_attributes(external: true)
        end
83

84
        it { is_expected.to eq([public_project]) }
85 86
      end
    end
87 88 89 90

    context "all" do
      it { is_expected.to match_array([shared_project_3, shared_project_2, shared_project_1, public_project]) }
    end
91 92 93 94
  end

  describe "no user" do
    context "only shared" do
95 96 97
      let(:options) { { only_shared: true } }

      it { is_expected.to match_array([shared_project_3, shared_project_1]) }
98 99 100
    end

    context "only owned" do
101 102 103
      let(:options) { { only_owned: true } }

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