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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
describe "skip_level?" do
|
|
|
|
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
|
|
|
|
|
|
|
it "skips levels" do
|
|
|
|
expect(skip_level?(fork_project, Gitlab::VisibilityLevel::PUBLIC)).to be_truthy
|
|
|
|
expect(skip_level?(fork_project, Gitlab::VisibilityLevel::INTERNAL)).to be_falsey
|
|
|
|
expect(skip_level?(fork_project, Gitlab::VisibilityLevel::PRIVATE)).to be_falsey
|
|
|
|
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
|
|
|
|
|
|
|
it "skips levels" do
|
|
|
|
expect(skip_level?(project, Gitlab::VisibilityLevel::PUBLIC)).to be_falsey
|
|
|
|
expect(skip_level?(project, Gitlab::VisibilityLevel::INTERNAL)).to be_falsey
|
|
|
|
expect(skip_level?(project, 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
|
|
|
|
|
|
|
it "skips levels" do
|
|
|
|
expect(skip_level?(snippet, Gitlab::VisibilityLevel::PUBLIC)).to be_falsey
|
|
|
|
expect(skip_level?(snippet, Gitlab::VisibilityLevel::INTERNAL)).to be_falsey
|
|
|
|
expect(skip_level?(snippet, Gitlab::VisibilityLevel::PRIVATE)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-04-26 01:01:52 -04:00
|
|
|
end
|