BigW Consortium Gitlab

visibility_level_spec.rb 1.58 KB
Newer Older
1 2
require 'spec_helper'

3
describe Gitlab::VisibilityLevel do
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  describe '.level_value' do
    it 'converts "public" to integer value' do
      expect(described_class.level_value('public')).to eq(Gitlab::VisibilityLevel::PUBLIC)
    end

    it 'converts string integer to integer value' do
      expect(described_class.level_value('20')).to eq(20)
    end

    it 'defaults to PRIVATE when string value is not valid' do
      expect(described_class.level_value('invalid')).to eq(Gitlab::VisibilityLevel::PRIVATE)
    end

    it 'defaults to PRIVATE when integer value is not valid' do
      expect(described_class.level_value(100)).to eq(Gitlab::VisibilityLevel::PRIVATE)
    end
  end
21 22 23

  describe '.levels_for_user' do
    it 'returns all levels for an admin' do
24
      user = build(:user, :admin)
25

26 27 28 29
      expect(described_class.levels_for_user(user))
        .to eq([Gitlab::VisibilityLevel::PRIVATE,
                Gitlab::VisibilityLevel::INTERNAL,
                Gitlab::VisibilityLevel::PUBLIC])
30 31 32
    end

    it 'returns INTERNAL and PUBLIC for internal users' do
33
      user = build(:user)
34

35 36 37
      expect(described_class.levels_for_user(user))
        .to eq([Gitlab::VisibilityLevel::INTERNAL,
                Gitlab::VisibilityLevel::PUBLIC])
38 39 40
    end

    it 'returns PUBLIC for external users' do
41
      user = build(:user, :external)
42

43 44
      expect(described_class.levels_for_user(user))
        .to eq([Gitlab::VisibilityLevel::PUBLIC])
45 46 47
    end

    it 'returns PUBLIC when no user is given' do
48 49
      expect(described_class.levels_for_user)
        .to eq([Gitlab::VisibilityLevel::PUBLIC])
50 51
    end
  end
52
end