debian-mirror-gitlab/spec/lib/gitlab/visibility_level_checker_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.6 KiB
Ruby
Raw Permalink Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2019-09-04 21:01:54 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::VisibilityLevelChecker do
2019-09-04 21:01:54 +05:30
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:override_params) { {} }
describe '#level_restricted?' do
2021-01-03 14:25:43 +05:30
subject(:result) { described_class.new(user, project, project_params: override_params).level_restricted? }
2019-09-04 21:01:54 +05:30
context 'when visibility level is allowed' do
it 'returns false with nil for visibility level' do
expect(result.restricted?).to eq(false)
expect(result.visibility_level).to be_nil
end
end
context 'when visibility level is restricted' do
before do
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
end
2021-01-03 14:25:43 +05:30
context 'for public project' do
before do
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
end
context 'for non-admin user' do
it 'returns true and visibility name' do
expect(result.restricted?).to eq(true)
expect(result.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC)
end
end
context 'for admin user' do
let(:user) { create(:user, :admin) }
2019-09-04 21:01:54 +05:30
2021-01-03 14:25:43 +05:30
it 'returns false and a nil visibility level' do
expect(result.restricted?).to eq(false)
expect(result.visibility_level).to be_nil
end
end
2019-09-04 21:01:54 +05:30
end
context 'overridden visibility' do
let(:override_params) do
{
import_data: {
data: {
override_params: {
visibility: override_visibility
}
}
}
}
end
context 'when restricted' do
let(:override_visibility) { 'public' }
it 'returns true and visibility name' do
expect(result.restricted?).to eq(true)
expect(result.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC)
end
end
context 'when misspelled' do
let(:override_visibility) { 'publik' }
it 'returns false with nil for visibility level' do
expect(result.restricted?).to eq(false)
expect(result.visibility_level).to be_nil
end
end
context 'when import_data is missing' do
let(:override_params) { {} }
it 'returns false with nil for visibility level' do
expect(result.restricted?).to eq(false)
expect(result.visibility_level).to be_nil
end
end
end
end
end
end