Welcome to mirror list, hosted at ThFree Co, Russian Federation.

trigger_variable_entity_spec.rb « serializers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: deabbb9d54b6e9fee0d3f870e402fa23a3f8d670 (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe TriggerVariableEntity do
  let(:project) { create(:project) }
  let(:request) { double('request') }
  let(:user) { create(:user) }
  let(:variable) { { key: 'TEST_KEY', value: 'TEST_VALUE' } }

  subject { described_class.new(variable, request: request).as_json }

  before do
    allow(request).to receive(:current_user).and_return(user)
    allow(request).to receive(:project).and_return(project)
  end

  it 'exposes the variable key' do
    expect(subject).to include(:key)
  end

  context 'when user has access to the value' do
    context 'when user is maintainer' do
      before do
        project.team.add_maintainer(user)
      end

      it 'exposes the variable value' do
        expect(subject).to include(:value)
      end
    end

    context 'when user is owner' do
      let(:user) { project.first_owner }

      it 'exposes the variable value' do
        expect(subject).to include(:value)
      end
    end
  end

  context 'when user does not have access to the value' do
    before do
      project.team.add_developer(user)
    end

    it 'does not expose the variable value' do
      expect(subject).not_to include(:value)
    end
  end
end