2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-02 12:25:12 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::VariablesController do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-02-02 12:25:12 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-02-02 12:25:12 -05:00
|
|
|
end
|
|
|
|
|
2018-01-29 12:39:06 -05:00
|
|
|
describe 'GET #show' do
|
2018-02-02 13:35:00 -05:00
|
|
|
let!(:variable) { create(:ci_variable, project: project) }
|
2018-01-29 12:39:06 -05:00
|
|
|
|
|
|
|
subject do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }, format: :json
|
2018-01-29 12:39:06 -05:00
|
|
|
end
|
|
|
|
|
2018-02-02 13:35:00 -05:00
|
|
|
include_examples 'GET #show lists all variables'
|
2018-01-29 12:39:06 -05:00
|
|
|
end
|
|
|
|
|
2018-02-02 13:35:00 -05:00
|
|
|
describe 'PATCH #update' do
|
|
|
|
let!(:variable) { create(:ci_variable, project: project) }
|
|
|
|
let(:owner) { project }
|
2018-02-02 12:54:13 -05:00
|
|
|
|
|
|
|
subject do
|
|
|
|
patch :update,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
variables_attributes: variables_attributes
|
|
|
|
},
|
2018-02-02 12:54:13 -05:00
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
|
2018-02-02 13:35:00 -05:00
|
|
|
include_examples 'PATCH #update updates variables'
|
2019-08-08 14:51:52 -04:00
|
|
|
|
|
|
|
context 'with environment scope' do
|
|
|
|
let!(:variable) { create(:ci_variable, project: project, environment_scope: 'custom_scope') }
|
|
|
|
|
|
|
|
let(:variable_attributes) do
|
|
|
|
{ id: variable.id,
|
|
|
|
key: variable.key,
|
|
|
|
secret_value: variable.value,
|
|
|
|
protected: variable.protected?.to_s,
|
|
|
|
environment_scope: variable.environment_scope }
|
|
|
|
end
|
|
|
|
let(:new_variable_attributes) do
|
|
|
|
{ key: 'new_key',
|
|
|
|
secret_value: 'dummy_value',
|
|
|
|
protected: 'false',
|
|
|
|
environment_scope: 'new_scope' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with same key and different environment scope' do
|
|
|
|
let(:variables_attributes) do
|
|
|
|
[
|
|
|
|
variable_attributes,
|
|
|
|
new_variable_attributes.merge(key: variable.key)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update the existing variable' do
|
|
|
|
expect { subject }.not_to change { variable.reload.value }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the new variable' do
|
|
|
|
expect { subject }.to change { owner.variables.count }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a successful response including all variables' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to match_response_schema('variables')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with same key and same environment scope' do
|
|
|
|
let(:variables_attributes) do
|
|
|
|
[
|
|
|
|
variable_attributes,
|
|
|
|
new_variable_attributes.merge(key: variable.key, environment_scope: variable.environment_scope)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update the existing variable' do
|
|
|
|
expect { subject }.not_to change { variable.reload.value }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create the new variable' do
|
|
|
|
expect { subject }.not_to change { owner.variables.count }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a bad request response' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-12 16:39:42 -05:00
|
|
|
end
|
2017-02-02 12:25:12 -05:00
|
|
|
end
|