summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/variables_controller_spec.rb
blob: 9fde65442153b59b2e755616f74523f51807fcfc (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
require 'spec_helper'

describe Projects::VariablesController do
  let(:project) { create(:project) }
  let(:user) { create(:user) }

  before do
    sign_in(user)
    project.add_master(user)
  end

  describe 'POST #create' do
    context 'variable is valid' do
      it 'shows a success flash message' do
        post :create, namespace_id: project.namespace.to_param, project_id: project,
                      variable: { key: "one", value: "two" }

        expect(flash[:notice]).to include 'Variable was successfully created.'
        expect(response).to redirect_to(project_settings_ci_cd_path(project))
      end
    end

    context 'variable is invalid' do
      it 'renders show' do
        post :create, namespace_id: project.namespace.to_param, project_id: project,
                      variable: { key: "..one", value: "two" }

        expect(response).to render_template("projects/variables/show")
      end
    end
  end

  describe 'POST #update' do
    let(:variable) { create(:ci_variable) }

    context 'updating a variable with valid characters' do
      before do
        project.variables << variable
      end

      it 'shows a success flash message' do
        post :update, namespace_id: project.namespace.to_param, project_id: project,
                      id: variable.id, variable: { key: variable.key, value: 'two' }

        expect(flash[:notice]).to include 'Variable was successfully updated.'
        expect(response).to redirect_to(project_variables_path(project))
      end

      it 'renders the action #show if the variable key is invalid' do
        post :update, namespace_id: project.namespace.to_param, project_id: project,
                      id: variable.id, variable: { key: '?', value: variable.value }

        expect(response).to have_gitlab_http_status(200)
        expect(response).to render_template :show
      end
    end
  end
end