2015-09-11 14:41:01 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe VisibilityLevelHelper do
|
2015-12-23 02:04:40 +05:30
|
|
|
let(:project) { build(:project) }
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:group) { build(:group) }
|
2015-12-23 02:04:40 +05:30
|
|
|
let(:personal_snippet) { build(:personal_snippet) }
|
|
|
|
let(:project_snippet) { build(:project_snippet) }
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
describe 'visibility_level_description' do
|
2015-12-23 02:04:40 +05:30
|
|
|
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-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
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-23 02:04:40 +05:30
|
|
|
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-09-11 14:41:01 +05:30
|
|
|
end
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
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-09-11 14:41:01 +05:30
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
it "describes public projects" do
|
|
|
|
expect(project_visibility_level_description(Gitlab::VisibilityLevel::PUBLIC))
|
|
|
|
.to eq "The project can be cloned without any authentication."
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
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-09-11 14:41:01 +05:30
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
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-09-11 14:41:01 +05:30
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
it 'defaults to personal snippet' do
|
|
|
|
expect(snippet_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE))
|
|
|
|
.to eq "The snippet is visible only to me."
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "skip_level?" do
|
|
|
|
describe "forks" do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:project) { create(:project, :internal) }
|
|
|
|
let(:fork_project) { create(:project, forked_from_project: project) }
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
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
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:project) { create(:project, :internal) }
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
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-06-02 11:05:42 +05:30
|
|
|
let(:snippet) { create(:snippet, :internal) }
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
end
|