BigW Consortium Gitlab

projects_finder_spec.rb 4.2 KB
Newer Older
1 2 3 4 5 6 7 8
require 'spec_helper'

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

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

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

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

    let!(:shared_project) do
21
      create(:project, :private, name: 'D', path: 'D')
22 23 24 25 26 27 28 29 30 31 32 33
    end

    let(:params) { {} }
    let(:current_user) { user }
    let(:project_ids_relation) { nil }
    let(:finder) { described_class.new(params: params, current_user: current_user) }

    subject { finder.execute.to_a }

    context 'without a user' do
      let(:current_user) { nil }

34
      it { is_expected.to match_array([shared_project, public_project, internal_project, private_project]) }
35 36 37
    end

    context 'with a user' do
38
      it { is_expected.to match_array([shared_project, public_project, internal_project, private_project]) }
39 40
    end

41 42 43 44 45 46
    context 'with pending delete project' do
      let!(:pending_delete_project) { create(:project, pending_delete: true) }

      it { is_expected.not_to include(pending_delete_project) }
    end

47 48
    context 'filter by namespace_id' do
      let(:namespace) { create(:namespace) }
49
      let!(:project_in_namespace) { create(:project, namespace: namespace) }
50 51 52 53 54 55 56 57 58 59 60 61 62
      let(:params) { { namespace_id: namespace.id } }

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

    context 'filter by visibility_level' do
      before do
        private_project.add_master(user)
      end

      context 'private' do
        let(:params) { { visibility_level: Gitlab::VisibilityLevel::PRIVATE } }

63
        it { is_expected.to match_array([shared_project, private_project]) }
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
      end

      context 'internal' do
        let(:params) { { visibility_level: Gitlab::VisibilityLevel::INTERNAL } }

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

      context 'public' do
        let(:params) { { visibility_level: Gitlab::VisibilityLevel::PUBLIC } }

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

    context 'filter by push' do
      let(:pushed_event) { create(:event, :pushed) }
      let!(:project_with_push) { pushed_event.project }
      let(:params) { { with_push: true } }

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

    context 'filter by abandoned' do
      before do
        private_project.update(last_activity_at: Time.zone.now - 6.months - 1.minute)
      end

      let(:params) { { abandoned: true } }

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

    context 'filter by last_repository_check_failed' do
      before do
        private_project.update(last_repository_check_failed: true)
      end

      let(:params) { { last_repository_check_failed: true } }

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

    context 'filter by archived' do
108
      let!(:archived_project) { create(:project, :public, :archived, name: 'E', path: 'E') }
109 110 111 112 113 114 115 116 117 118 119 120

      context 'archived=false' do
        let(:params) { { archived: false } }

        it { is_expected.to match_array([shared_project, public_project, internal_project, private_project]) }
      end

      context 'archived=true' do
        let(:params) { { archived: true } }

        it { is_expected.to match_array([archived_project, shared_project, public_project, internal_project, private_project]) }
      end
121 122 123 124 125 126

      context 'archived=only' do
        let(:params) { { archived: 'only' } }

        it { is_expected.to eq([archived_project]) }
      end
127 128 129
    end

    context 'filter by personal' do
130
      let!(:personal_project) { create(:project, namespace: user.namespace) }
131 132 133 134 135 136 137 138
      let(:params) { { personal: true } }

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

    context 'filter by name' do
      let(:params) { { name: 'C' } }

139
      it { is_expected.to match_array([shared_project, public_project, private_project]) }
140 141 142 143 144 145 146 147 148
    end

    context 'sorting' do
      let(:params) { { sort: 'name_asc' } }

      it { is_expected.to eq([private_project, internal_project, public_project, shared_project]) }
    end
  end
end