gitlab-org--gitlab-foss/spec/controllers/admin/ci/variables_controller_spec.rb

71 lines
1.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'spec_helper'
RSpec.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