summaryrefslogtreecommitdiff
path: root/spec/controllers/admin/ci/variables_controller_spec.rb
blob: 57f2dd21f39a0d4ef57765837484db3b333401e4 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

require 'spec_helper'

describe Admin::Ci::VariablesController do
  let_it_be(:variable) { create(:ci_instance_variable) }

  before do
    sign_in(user)
  end

  describe 'GET #show' do
    subject do
      get :show, params: {}, format: :json
    end

    context 'when signed in as admin' do
      let(:user) { create(:admin) }

      include_examples 'GET #show lists all variables'
    end

    context 'when signed in as regular user' do
      let(:user) { create(:user) }

      it 'returns 404' do
        subject

        expect(response).to have_gitlab_http_status(:not_found)
      end
    end
  end

  describe 'PATCH #update' do
    subject do
      patch :update,
        params: {
          variables_attributes: variables_attributes
        },
        format: :json
    end

    context 'when signed in as admin' do
      let(:user) { create(:admin) }

      include_examples 'PATCH #update updates variables' do
        let(:variables_scope) { Ci::InstanceVariable.all }
        let(:file_variables_scope) { variables_scope.file }
      end
    end

    context 'when signed in as regular user' do
      let(:user) { create(:user) }

      let(:variables_attributes) do
        [{
          id: variable.id,
          key: variable.key,
          secret_value: 'new value'
        }]
      end

      it 'returns 404' do
        subject

        expect(response).to have_gitlab_http_status(:not_found)
      end
    end
  end
end