diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/helpers/visibility_level_helper_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/helpers/visibility_level_helper_spec.rb')
-rw-r--r-- | spec/helpers/visibility_level_helper_spec.rb | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/spec/helpers/visibility_level_helper_spec.rb b/spec/helpers/visibility_level_helper_spec.rb index b7a88ee5010..3b4d82c65ac 100644 --- a/spec/helpers/visibility_level_helper_spec.rb +++ b/spec/helpers/visibility_level_helper_spec.rb @@ -184,6 +184,84 @@ describe VisibilityLevelHelper do end end + shared_examples_for 'available visibility level' do + using RSpec::Parameterized::TableSyntax + + let(:user) { create(:user) } + + subject { helper.available_visibility_levels(form_model) } + + public_vis = Gitlab::VisibilityLevel::PUBLIC + internal_vis = Gitlab::VisibilityLevel::INTERNAL + private_vis = Gitlab::VisibilityLevel::PRIVATE + + where(:restricted_visibility_levels, :expected) do + [] | [private_vis, internal_vis, public_vis] + [private_vis] | [internal_vis, public_vis] + [private_vis, internal_vis] | [public_vis] + [private_vis, public_vis] | [internal_vis] + [internal_vis] | [private_vis, public_vis] + [internal_vis, private_vis] | [public_vis] + [internal_vis, public_vis] | [private_vis] + [public_vis] | [private_vis, internal_vis] + [public_vis, private_vis] | [internal_vis] + [public_vis, internal_vis] | [private_vis] + end + + before do + allow(helper).to receive(:current_user) { user } + end + + with_them do + before do + stub_application_setting(restricted_visibility_levels: restricted_visibility_levels) + end + + it { is_expected.to eq(expected) } + end + + it 'excludes disallowed visibility levels' do + stub_application_setting(restricted_visibility_levels: []) + allow(helper).to receive(:disallowed_visibility_level?).with(form_model, private_vis) { true } + allow(helper).to receive(:disallowed_visibility_level?).with(form_model, internal_vis) { false } + allow(helper).to receive(:disallowed_visibility_level?).with(form_model, public_vis) { false } + + expect(subject).to eq([internal_vis, public_vis]) + end + end + + describe '#available_visibility_levels' do + it_behaves_like 'available visibility level' do + let(:form_model) { project_snippet } + end + + it_behaves_like 'available visibility level' do + let(:form_model) { personal_snippet } + end + + it_behaves_like 'available visibility level' do + let(:form_model) { project } + end + + it_behaves_like 'available visibility level' do + let(:form_model) { group } + end + end + + describe '#snippets_selected_visibility_level' do + let(:available_levels) { [Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL] } + + it 'returns the selected visibility level' do + expect(helper.snippets_selected_visibility_level(available_levels, Gitlab::VisibilityLevel::PUBLIC)) + .to eq(Gitlab::VisibilityLevel::PUBLIC) + end + + it "fallbacks using the lowest available visibility level when selected level isn't available" do + expect(helper.snippets_selected_visibility_level(available_levels, Gitlab::VisibilityLevel::PRIVATE)) + .to eq(Gitlab::VisibilityLevel::INTERNAL) + end + end + describe 'multiple_visibility_levels_restricted?' do using RSpec::Parameterized::TableSyntax |