2015-04-26 01:01:52 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe VisibilityLevelHelper do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { build(:project) }
|
2016-03-01 10:22:29 -05:00
|
|
|
let(:group) { build(:group) }
|
2015-12-07 07:37:01 -05:00
|
|
|
let(:personal_snippet) { build(:personal_snippet) }
|
|
|
|
let(:project_snippet) { build(:project_snippet) }
|
2015-04-26 01:01:52 -04:00
|
|
|
|
2018-07-23 05:39:03 -04:00
|
|
|
describe 'visibility_icon_description' do
|
|
|
|
context 'used with a Project' do
|
|
|
|
it 'delegates projects to #project_visibility_icon_description' do
|
|
|
|
expect(visibility_icon_description(project))
|
|
|
|
.to match /project/i
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'used with a ProjectPresenter' do
|
|
|
|
it 'delegates projects to #project_visibility_icon_description' do
|
|
|
|
expect(visibility_icon_description(project.present))
|
|
|
|
.to match /project/i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'used with a Group' do
|
|
|
|
it 'delegates groups to #group_visibility_icon_description' do
|
|
|
|
expect(visibility_icon_description(group))
|
|
|
|
.to match /group/i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 01:01:52 -04:00
|
|
|
describe 'visibility_level_description' do
|
2015-12-07 07:37:01 -05:00
|
|
|
context 'used with a Project' do
|
|
|
|
it 'delegates projects to #project_visibility_level_description' do
|
|
|
|
expect(visibility_level_description(Gitlab::VisibilityLevel::PRIVATE, project))
|
|
|
|
.to match /project/i
|
2015-04-26 01:01:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-01 10:22:29 -05:00
|
|
|
context 'used with a Group' do
|
|
|
|
it 'delegates groups to #group_visibility_level_description' do
|
|
|
|
expect(visibility_level_description(Gitlab::VisibilityLevel::PRIVATE, group))
|
|
|
|
.to match /group/i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-07 07:37:01 -05:00
|
|
|
context 'called with a Snippet' do
|
|
|
|
it 'delegates snippets to #snippet_visibility_level_description' do
|
|
|
|
expect(visibility_level_description(Gitlab::VisibilityLevel::INTERNAL, project_snippet))
|
|
|
|
.to match /snippet/i
|
2015-04-26 01:01:52 -04:00
|
|
|
end
|
2015-12-07 07:37:01 -05:00
|
|
|
end
|
|
|
|
end
|
2015-04-26 01:01:52 -04:00
|
|
|
|
2015-12-07 07:37:01 -05:00
|
|
|
describe "#project_visibility_level_description" do
|
|
|
|
it "describes private projects" do
|
|
|
|
expect(project_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE))
|
|
|
|
.to eq "Project access must be granted explicitly to each user."
|
|
|
|
end
|
2015-04-26 01:01:52 -04:00
|
|
|
|
2015-12-07 07:37:01 -05:00
|
|
|
it "describes public projects" do
|
|
|
|
expect(project_visibility_level_description(Gitlab::VisibilityLevel::PUBLIC))
|
2017-06-06 04:28:39 -04:00
|
|
|
.to eq "The project can be accessed without any authentication."
|
2015-04-26 01:01:52 -04:00
|
|
|
end
|
2015-12-07 07:37:01 -05:00
|
|
|
end
|
2015-04-26 01:01:52 -04:00
|
|
|
|
2015-12-07 07:37:01 -05:00
|
|
|
describe "#snippet_visibility_level_description" do
|
|
|
|
it 'describes visibility only for me' do
|
|
|
|
expect(snippet_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE, personal_snippet))
|
|
|
|
.to eq "The snippet is visible only to me."
|
|
|
|
end
|
2015-04-26 01:01:52 -04:00
|
|
|
|
2015-12-07 07:37:01 -05:00
|
|
|
it 'describes visibility for project members' do
|
|
|
|
expect(snippet_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE, project_snippet))
|
|
|
|
.to eq "The snippet is visible only to project members."
|
|
|
|
end
|
2015-04-26 01:01:52 -04:00
|
|
|
|
2015-12-07 07:37:01 -05:00
|
|
|
it 'defaults to personal snippet' do
|
|
|
|
expect(snippet_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE))
|
|
|
|
.to eq "The snippet is visible only to me."
|
2015-04-26 01:01:52 -04:00
|
|
|
end
|
|
|
|
end
|
2015-07-06 08:38:43 -04:00
|
|
|
|
2017-08-24 18:24:29 -04:00
|
|
|
describe "disallowed_visibility_level?" do
|
2015-07-06 08:38:43 -04:00
|
|
|
describe "forks" do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :internal) }
|
|
|
|
let(:fork_project) { create(:project, forked_from_project: project) }
|
2015-07-06 08:38:43 -04:00
|
|
|
|
2017-08-24 18:24:29 -04:00
|
|
|
it "disallows levels" do
|
|
|
|
expect(disallowed_visibility_level?(fork_project, Gitlab::VisibilityLevel::PUBLIC)).to be_truthy
|
|
|
|
expect(disallowed_visibility_level?(fork_project, Gitlab::VisibilityLevel::INTERNAL)).to be_falsey
|
|
|
|
expect(disallowed_visibility_level?(fork_project, Gitlab::VisibilityLevel::PRIVATE)).to be_falsey
|
2015-07-06 08:38:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "non-forked project" do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :internal) }
|
2015-07-06 08:38:43 -04:00
|
|
|
|
2017-08-24 18:24:29 -04:00
|
|
|
it "disallows levels" do
|
|
|
|
expect(disallowed_visibility_level?(project, Gitlab::VisibilityLevel::PUBLIC)).to be_falsey
|
|
|
|
expect(disallowed_visibility_level?(project, Gitlab::VisibilityLevel::INTERNAL)).to be_falsey
|
|
|
|
expect(disallowed_visibility_level?(project, Gitlab::VisibilityLevel::PRIVATE)).to be_falsey
|
2015-07-06 08:38:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-24 18:55:43 -04:00
|
|
|
describe "group" do
|
|
|
|
let(:group) { create(:group, :internal) }
|
|
|
|
|
|
|
|
it "disallows levels" do
|
|
|
|
expect(disallowed_visibility_level?(group, Gitlab::VisibilityLevel::PUBLIC)).to be_falsey
|
|
|
|
expect(disallowed_visibility_level?(group, Gitlab::VisibilityLevel::INTERNAL)).to be_falsey
|
|
|
|
expect(disallowed_visibility_level?(group, Gitlab::VisibilityLevel::PRIVATE)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "sub-group" do
|
|
|
|
let(:group) { create(:group, :private) }
|
|
|
|
let(:subgroup) { create(:group, :private, parent: group) }
|
|
|
|
|
|
|
|
it "disallows levels" do
|
|
|
|
expect(disallowed_visibility_level?(subgroup, Gitlab::VisibilityLevel::PUBLIC)).to be_truthy
|
|
|
|
expect(disallowed_visibility_level?(subgroup, Gitlab::VisibilityLevel::INTERNAL)).to be_truthy
|
|
|
|
expect(disallowed_visibility_level?(subgroup, Gitlab::VisibilityLevel::PRIVATE)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "snippet" do
|
2016-03-08 16:40:45 -05:00
|
|
|
let(:snippet) { create(:snippet, :internal) }
|
2015-07-06 08:38:43 -04:00
|
|
|
|
2017-08-24 18:24:29 -04:00
|
|
|
it "disallows levels" do
|
|
|
|
expect(disallowed_visibility_level?(snippet, Gitlab::VisibilityLevel::PUBLIC)).to be_falsey
|
|
|
|
expect(disallowed_visibility_level?(snippet, Gitlab::VisibilityLevel::INTERNAL)).to be_falsey
|
|
|
|
expect(disallowed_visibility_level?(snippet, Gitlab::VisibilityLevel::PRIVATE)).to be_falsey
|
2015-07-06 08:38:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-25 16:40:21 -04:00
|
|
|
|
|
|
|
describe "disallowed_visibility_level_description" do
|
|
|
|
let(:group) { create(:group, :internal) }
|
|
|
|
let!(:subgroup) { create(:group, :internal, parent: group) }
|
|
|
|
let!(:project) { create(:project, :internal, group: group) }
|
|
|
|
|
|
|
|
describe "project" do
|
|
|
|
it "provides correct description for disabled levels" do
|
|
|
|
expect(disallowed_visibility_level?(project, Gitlab::VisibilityLevel::PUBLIC)).to be_truthy
|
2017-08-30 16:51:03 -04:00
|
|
|
expect(strip_tags disallowed_visibility_level_description(Gitlab::VisibilityLevel::PUBLIC, project))
|
2017-08-25 16:40:21 -04:00
|
|
|
.to include "the visibility of #{project.group.name} is internal"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "group" do
|
|
|
|
it "provides correct description for disabled levels" do
|
|
|
|
expect(disallowed_visibility_level?(group, Gitlab::VisibilityLevel::PRIVATE)).to be_truthy
|
|
|
|
expect(disallowed_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE, group))
|
|
|
|
.to include "it contains projects with higher visibility", "it contains sub-groups with higher visibility"
|
|
|
|
|
|
|
|
expect(disallowed_visibility_level?(subgroup, Gitlab::VisibilityLevel::PUBLIC)).to be_truthy
|
2017-08-30 17:01:57 -04:00
|
|
|
expect(strip_tags disallowed_visibility_level_description(Gitlab::VisibilityLevel::PUBLIC, subgroup))
|
|
|
|
.to include "the visibility of #{group.name} is internal"
|
2017-08-25 16:40:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-04-26 01:01:52 -04:00
|
|
|
end
|