Commit 5243de82 authored by Aleksei Lipniagov's avatar Aleksei Lipniagov

Add unit tests

parent ac53b960
......@@ -2258,7 +2258,6 @@ class Project < ApplicationRecord
setting
end
# TODO: unit test this method
def correct_visibility_level
if group && group.visibility_level < visibility_level
self.visibility_level = group.visibility_level
......
......@@ -5179,6 +5179,61 @@ describe Project do
end
end
describe '#correct_visibility_level' do
context 'when has a group' do
let(:group) { create(:group, visibility_level: group_visibility_level) }
let(:project) { build(:project, namespace: group, visibility_level: project_visibility_level) }
context 'when the group `visibility_level` is more strict' do
let(:group_visibility_level) { Gitlab::VisibilityLevel::PRIVATE }
let(:project_visibility_level) { Gitlab::VisibilityLevel::INTERNAL }
it 'sets `visibility_level` value from the group' do
expect { project.correct_visibility_level }
.to change { project.visibility_level }
.to(Gitlab::VisibilityLevel::PRIVATE)
end
end
context 'when the group `visibility_level` is less strict' do
let(:group_visibility_level) { Gitlab::VisibilityLevel::INTERNAL }
let(:project_visibility_level) { Gitlab::VisibilityLevel::PRIVATE }
it 'does not change the value of the `visibility_level` field' do
expect { project.correct_visibility_level }
.not_to change { project.visibility_level }
end
end
end
context 'when `restricted_visibility_levels` of the GitLab instance exist' do
before do
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL])
end
let(:project) { build(:project, visibility_level: project_visibility_level) }
context 'when `visibility_level` is included into `restricted_visibility_levels`' do
let(:project_visibility_level) { Gitlab::VisibilityLevel::INTERNAL }
it 'sets `visibility_level` value to `PRIVATE`' do
expect { project.correct_visibility_level }
.to change { project.visibility_level }
.to(Gitlab::VisibilityLevel::PRIVATE)
end
end
context 'when `restricted_visibility_levels` does not include `visibility_level`' do
let(:project_visibility_level) { Gitlab::VisibilityLevel::PUBLIC }
it 'does not change the value of the `visibility_level` field' do
expect { project.correct_visibility_level }
.to not_change { project.visibility_level }
end
end
end
end
def rugged_config
rugged_repo(project.repository).config
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment