gitlab-org--gitlab-foss/spec/lib/gitlab/visibility_level_spec.rb

80 lines
2.7 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Gitlab::VisibilityLevel do
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
2017-06-13 10:44:55 -04:00
describe '.levels_for_user' do
it 'returns all levels for an admin' do
user = build(:user, :admin)
2017-06-13 10:44:55 -04:00
2017-06-21 09:48:12 -04:00
expect(described_class.levels_for_user(user))
.to eq([Gitlab::VisibilityLevel::PRIVATE,
Gitlab::VisibilityLevel::INTERNAL,
Gitlab::VisibilityLevel::PUBLIC])
2017-06-13 10:44:55 -04:00
end
it 'returns INTERNAL and PUBLIC for internal users' do
user = build(:user)
2017-06-13 10:44:55 -04:00
2017-06-21 09:48:12 -04:00
expect(described_class.levels_for_user(user))
.to eq([Gitlab::VisibilityLevel::INTERNAL,
Gitlab::VisibilityLevel::PUBLIC])
2017-06-13 10:44:55 -04:00
end
it 'returns PUBLIC for external users' do
user = build(:user, :external)
2017-06-13 10:44:55 -04:00
2017-06-21 09:48:12 -04:00
expect(described_class.levels_for_user(user))
.to eq([Gitlab::VisibilityLevel::PUBLIC])
2017-06-13 10:44:55 -04:00
end
it 'returns PUBLIC when no user is given' do
2017-06-21 09:48:12 -04:00
expect(described_class.levels_for_user)
.to eq([Gitlab::VisibilityLevel::PUBLIC])
2017-06-13 10:44:55 -04:00
end
end
describe '.allowed_levels' do
it 'only includes the levels that arent restricted' do
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL])
expect(described_class.allowed_levels)
.to contain_exactly(described_class::PRIVATE, described_class::PUBLIC)
end
end
describe '.closest_allowed_level' do
it 'picks INTERNAL instead of PUBLIC if public is restricted' do
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
expect(described_class.closest_allowed_level(described_class::PUBLIC))
.to eq(described_class::INTERNAL)
end
it 'picks PRIVATE if nothing is available' do
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC,
Gitlab::VisibilityLevel::INTERNAL,
Gitlab::VisibilityLevel::PRIVATE])
expect(described_class.closest_allowed_level(described_class::PUBLIC))
.to eq(described_class::PRIVATE)
end
end
end