File: project_group_link_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (83 lines) | stat: -rw-r--r-- 3,041 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ProjectGroupLink, feature_category: :groups_and_projects do
  describe "Associations" do
    it { is_expected.to belong_to(:group) }
    it { is_expected.to belong_to(:project) }
  end

  describe "Validation" do
    let(:parent_group) { create(:group) }
    let(:group) { create(:group, parent: parent_group) }
    let(:project) { create(:project, group: group) }
    let!(:project_group_link) { create(:project_group_link, project: project) }

    it { is_expected.to validate_presence_of(:project_id) }
    it { is_expected.to validate_uniqueness_of(:group_id).scoped_to(:project_id).with_message(/already shared/) }
    it { is_expected.to validate_presence_of(:group) }
    it { is_expected.to validate_presence_of(:group_access) }
    it { is_expected.to validate_inclusion_of(:group_access).in_array(Gitlab::Access.all_values) }

    it "doesn't allow a project to be shared with the group it is in" do
      project_group_link.group = group

      expect(project_group_link).not_to be_valid
    end

    it "doesn't allow a project to be shared with an ancestor of the group it is in" do
      project_group_link.group = parent_group

      expect(project_group_link).not_to be_valid
    end
  end

  describe 'scopes' do
    describe '.non_guests' do
      let!(:project_group_link_reporter) { create :project_group_link, :reporter }
      let!(:project_group_link_maintainer) { create :project_group_link, :maintainer }
      let!(:project_group_link_developer) { create :project_group_link }
      let!(:project_group_link_guest) { create :project_group_link, :guest }

      it 'returns all records which are greater than Guests access' do
        expect(described_class.non_guests).to match_array([
          project_group_link_reporter,
                                                            project_group_link_developer,
                                                            project_group_link_maintainer
        ])
      end
    end
  end

  describe 'search by group name' do
    let_it_be(:project_group_link) { create(:project_group_link) }
    let_it_be(:group) { project_group_link.group }

    it { expect(described_class.search(group.name)).to eq([project_group_link]) }
    it { expect(described_class.search('not-a-group-name')).to be_empty }
  end

  describe '#owner_access?' do
    it 'returns true for links with OWNER access' do
      link = create(:project_group_link, :owner)

      expect(link.owner_access?).to eq(true)
    end

    it 'returns false for links without OWNER access' do
      link = create(:project_group_link, :guest)

      expect(link.owner_access?).to eq(false)
    end
  end

  describe '#human_access' do
    it 'delegates to Gitlab::Access' do
      project_group_link = create(:project_group_link, :reporter)
      expect(Gitlab::Access).to receive(:human_access).with(project_group_link.group_access).and_call_original

      expect(project_group_link.human_access).to eq('Reporter')
    end
  end
end