summaryrefslogtreecommitdiff
path: root/spec/features/variables_spec.rb
blob: d0c982919db570fc1177b9ded6860dc1ec082d83 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
require 'spec_helper'

describe 'Project variables', js: true do
  let(:user)     { create(:user) }
  let(:project)  { create(:empty_project) }
  let(:variable) { create(:ci_variable, key: 'test_key', value: 'test value') }

  before do
    login_as(user)
    project.team << [user, :master]
    project.variables << variable

    visit namespace_project_settings_ci_cd_path(project.namespace, project)
  end

  it 'shows list of variables' do
    page.within('.variables-table') do
      expect(page).to have_content(variable.key)
    end
  end

  it 'adds new secret variable' do
    fill_in('variable_key', with: 'key')
    fill_in('variable_value', with: 'key value')
    click_button('Add new variable')

    expect(page).to have_content('Variables were successfully updated.')
    page.within('.variables-table') do
      expect(page).to have_content('key')
      expect(page).to have_content('No')
    end
  end

  it 'adds empty variable' do
    fill_in('variable_key', with: 'new_key')
    fill_in('variable_value', with: '')
    click_button('Add new variable')

    expect(page).to have_content('Variables were successfully updated.')
    page.within('.variables-table') do
      expect(page).to have_content('new_key')
    end
  end

  it 'adds new protected variable' do
    fill_in('variable_key', with: 'key')
    fill_in('variable_value', with: 'value')
    check('Protected')
    click_button('Add new variable')

    expect(page).to have_content('Variables were successfully updated.')
    page.within('.variables-table') do
      expect(page).to have_content('key')
      expect(page).to have_content('Yes')
    end
  end

  it 'reveals and hides new variable' do
    fill_in('variable_key', with: 'key')
    fill_in('variable_value', with: 'key value')
    click_button('Add new variable')

    page.within('.variables-table') do
      expect(page).to have_content('key')
      expect(page).to have_content('******')
    end

    click_button('Reveal Values')

    page.within('.variables-table') do
      expect(page).to have_content('key')
      expect(page).to have_content('key value')
    end

    click_button('Hide Values')

    page.within('.variables-table') do
      expect(page).to have_content('key')
      expect(page).to have_content('******')
    end
  end

  it 'deletes variable' do
    page.within('.variables-table') do
      find('.btn-variable-delete').click
    end

    expect(page).not_to have_selector('variables-table')
  end

  it 'edits variable' do
    page.within('.variables-table') do
      find('.btn-variable-edit').click
    end

    expect(page).to have_content('Update variable')
    fill_in('variable_key', with: 'key')
    fill_in('variable_value', with: 'key value')
    click_button('Save variable')

    expect(page).to have_content('Variable was successfully updated.')
    expect(project.variables(true).first.value).to eq('key value')
  end

  it 'edits variable with empty value' do
    page.within('.variables-table') do
      find('.btn-variable-edit').click
    end

    expect(page).to have_content('Update variable')
    fill_in('variable_value', with: '')
    click_button('Save variable')

    expect(page).to have_content('Variable was successfully updated.')
    expect(project.variables(true).first.value).to eq('')
  end

  it 'edits variable to be protected' do
    page.within('.variables-table') do
      find('.btn-variable-edit').click
    end

    expect(page).to have_content('Update variable')
    check('Protected')
    click_button('Save variable')

    expect(page).to have_content('Variable was successfully updated.')
    expect(project.variables(true).first).to be_protected
  end

  it 'edits variable to be unprotected' do
    project.variables.first.update(protected: true)

    page.within('.variables-table') do
      find('.btn-variable-edit').click
    end

    expect(page).to have_content('Update variable')
    uncheck('Protected')
    click_button('Save variable')

    expect(page).to have_content('Variable was successfully updated.')
    expect(project.variables(true).first).not_to be_protected
  end
end