summaryrefslogtreecommitdiff
path: root/spec/controllers/admin/ci/variables_controller_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/admin/ci/variables_controller_spec.rb')
-rw-r--r--spec/controllers/admin/ci/variables_controller_spec.rb70
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/controllers/admin/ci/variables_controller_spec.rb b/spec/controllers/admin/ci/variables_controller_spec.rb
new file mode 100644
index 00000000000..57f2dd21f39
--- /dev/null
+++ b/spec/controllers/admin/ci/variables_controller_spec.rb
@@ -0,0 +1,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