BigW Consortium Gitlab

visibility_level_helper_spec.rb 3.42 KB
Newer Older
Vinnie Okada committed
1 2 3
require 'spec_helper'

describe VisibilityLevelHelper do
4
  let(:project)          { build(:project) }
5
  let(:group)            { build(:group) }
6 7
  let(:personal_snippet) { build(:personal_snippet) }
  let(:project_snippet)  { build(:project_snippet) }
Vinnie Okada committed
8 9

  describe 'visibility_level_description' do
10 11 12 13
    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
Vinnie Okada committed
14 15 16
      end
    end

17 18 19 20 21 22 23
    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

24 25 26 27
    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
Vinnie Okada committed
28
      end
29 30
    end
  end
Vinnie Okada committed
31

32 33 34 35 36
  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
Vinnie Okada committed
37

38 39 40
    it "describes public projects" do
      expect(project_visibility_level_description(Gitlab::VisibilityLevel::PUBLIC))
            .to eq "The project can be cloned without any authentication."
Vinnie Okada committed
41
    end
42
  end
Vinnie Okada committed
43

44 45 46 47 48
  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
Vinnie Okada committed
49

50 51 52 53
    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
Vinnie Okada committed
54

55 56 57
    it 'defaults to personal snippet' do
      expect(snippet_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE))
            .to eq "The snippet is visible only to me."
Vinnie Okada committed
58 59
    end
  end
60 61 62

  describe "skip_level?" do
    describe "forks" do
63 64
      let(:project)       { create(:project, :internal) }
      let(:fork_project)  { create(:project, forked_from_project: project) }
65 66 67 68 69 70 71 72 73

      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
74
      let(:project) { create(:project, :internal) }
75 76 77 78 79 80 81 82 83

      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
84
      let(:snippet) { create(:snippet, :internal) }
85 86 87 88 89 90 91 92

      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
Vinnie Okada committed
93
end