File: reference_parser_shared_examples.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 (53 lines) | stat: -rw-r--r-- 1,494 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
# frozen_string_literal: true

RSpec.shared_examples "referenced feature visibility" do |*related_features|
  let(:enable_user?) { false }
  let(:feature_fields) do
    related_features.map { |feature| (feature + "_access_level").to_sym }
  end

  before do
    link['data-project'] = project.id.to_s
  end

  context "when feature is disabled" do
    it "does not create reference" do
      set_features_fields_to(ProjectFeature::DISABLED)
      expect(subject.nodes_visible_to_user(user, [link])).to eq([])
    end
  end

  context "when feature is enabled only for team members" do
    before do
      set_features_fields_to(ProjectFeature::PRIVATE)
    end

    it "does not create reference for non member" do
      non_member = create(:user)

      expect(subject.nodes_visible_to_user(non_member, [link])).to eq([])
    end

    it "creates reference for member" do
      project.add_developer(user)

      expect(subject.nodes_visible_to_user(user, [link])).to eq([link])
    end
  end

  context "when feature is enabled" do
    # Allows implementing specs to enable finer-tuned permissions
    let(:enable_user?) { true }

    it "creates reference" do
      # The project is public
      set_features_fields_to(ProjectFeature::ENABLED)

      expect(subject.nodes_visible_to_user(user, [link])).to eq([link])
    end
  end

  def set_features_fields_to(visibility_level)
    feature_fields.each { |field| project.project_feature.update_attribute(field, visibility_level) }
  end
end