guest_spec.rb 1.51 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'spec_helper'

5
describe Guest do
6 7 8
  set(:public_project) { create(:project, :public) }
  set(:private_project) { create(:project, :private) }
  set(:internal_project) { create(:project, :internal) }
9 10 11 12

  describe '.can_pull?' do
    context 'when project is private' do
      it 'does not allow to pull the repo' do
13
        expect(described_class.can?(:download_code, private_project)).to eq(false)
14 15 16 17 18
      end
    end

    context 'when project is internal' do
      it 'does not allow to pull the repo' do
19
        expect(described_class.can?(:download_code, internal_project)).to eq(false)
20 21 22 23 24 25 26 27
      end
    end

    context 'when project is public' do
      context 'when repository is disabled' do
        it 'does not allow to pull the repo' do
          public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::DISABLED)

28
          expect(described_class.can?(:download_code, public_project)).to eq(false)
29 30 31 32 33 34 35
        end
      end

      context 'when repository is accessible only by team members' do
        it 'does not allow to pull the repo' do
          public_project.project_feature.update_attribute(:repository_access_level, ProjectFeature::PRIVATE)

36
          expect(described_class.can?(:download_code, public_project)).to eq(false)
37 38 39 40 41
        end
      end

      context 'when repository is enabled' do
        it 'allows to pull the repo' do
42
          expect(described_class.can?(:download_code, public_project)).to eq(true)
43 44 45 46 47
        end
      end
    end
  end
end