2017-03-20 21:05:53 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::VisibilityLevel, lib: true 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 14:44:55 +00:00
|
|
|
|
|
|
|
describe '.levels_for_user' do
|
|
|
|
it 'returns all levels for an admin' do
|
2017-06-22 06:35:49 +00:00
|
|
|
user = build(:user, :admin)
|
2017-06-13 14:44:55 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(described_class.levels_for_user(user))
|
|
|
|
.to eq([Gitlab::VisibilityLevel::PRIVATE,
|
|
|
|
Gitlab::VisibilityLevel::INTERNAL,
|
|
|
|
Gitlab::VisibilityLevel::PUBLIC])
|
2017-06-13 14:44:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns INTERNAL and PUBLIC for internal users' do
|
2017-06-22 06:35:49 +00:00
|
|
|
user = build(:user)
|
2017-06-13 14:44:55 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(described_class.levels_for_user(user))
|
|
|
|
.to eq([Gitlab::VisibilityLevel::INTERNAL,
|
|
|
|
Gitlab::VisibilityLevel::PUBLIC])
|
2017-06-13 14:44:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns PUBLIC for external users' do
|
2017-06-22 06:35:49 +00:00
|
|
|
user = build(:user, :external)
|
2017-06-13 14:44:55 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(described_class.levels_for_user(user))
|
|
|
|
.to eq([Gitlab::VisibilityLevel::PUBLIC])
|
2017-06-13 14:44:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns PUBLIC when no user is given' do
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(described_class.levels_for_user)
|
|
|
|
.to eq([Gitlab::VisibilityLevel::PUBLIC])
|
2017-06-13 14:44:55 +00:00
|
|
|
end
|
|
|
|
end
|
2017-03-20 21:05:53 +00:00
|
|
|
end
|