2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'GET #show lists all variables' do
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'renders the variables as json' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to match_response_schema('variables')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has only one variable' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(json_response['variables'].count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'PATCH #update updates variables' do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:variable_attributes) do
|
|
|
|
{ id: variable.id,
|
|
|
|
key: variable.key,
|
2018-05-09 12:01:36 +05:30
|
|
|
secret_value: variable.value,
|
2018-03-17 18:26:18 +05:30
|
|
|
protected: variable.protected?.to_s }
|
|
|
|
end
|
|
|
|
let(:new_variable_attributes) do
|
|
|
|
{ key: 'new_key',
|
2018-05-09 12:01:36 +05:30
|
|
|
secret_value: 'dummy_value',
|
2018-03-17 18:26:18 +05:30
|
|
|
protected: 'false' }
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:variables_scope) { owner.variables }
|
|
|
|
let(:file_variables_scope) { owner.variables.file }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'with invalid new variable parameters' do
|
|
|
|
let(:variables_attributes) do
|
|
|
|
[
|
2018-05-09 12:01:36 +05:30
|
|
|
variable_attributes.merge(secret_value: 'other_value'),
|
2018-03-17 18:26:18 +05:30
|
|
|
new_variable_attributes.merge(key: '...?')
|
|
|
|
]
|
|
|
|
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
|
2020-05-24 23:13:21 +05:30
|
|
|
expect { subject }.not_to change { variables_scope.count }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a bad request response' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with duplicate new variable parameters' do
|
|
|
|
let(:variables_attributes) do
|
|
|
|
[
|
|
|
|
new_variable_attributes,
|
2018-05-09 12:01:36 +05:30
|
|
|
new_variable_attributes.merge(secret_value: 'other_value')
|
2018-03-17 18:26:18 +05:30
|
|
|
]
|
|
|
|
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
|
2020-05-24 23:13:21 +05:30
|
|
|
expect { subject }.not_to change { variables_scope.count }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a bad request response' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with valid new variable parameters' do
|
|
|
|
let(:variables_attributes) do
|
|
|
|
[
|
2018-05-09 12:01:36 +05:30
|
|
|
variable_attributes.merge(secret_value: 'other_value'),
|
2018-03-17 18:26:18 +05:30
|
|
|
new_variable_attributes
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the existing variable' do
|
|
|
|
expect { subject }.to change { variable.reload.value }.to('other_value')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the new variable' do
|
2020-05-24 23:13:21 +05:30
|
|
|
expect { subject }.to change { variables_scope.count }.by(1)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a successful response' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has all variables in response' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to match_response_schema('variables')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a deleted variable' do
|
|
|
|
let(:variables_attributes) { [variable_attributes.merge(_destroy: 'true')] }
|
|
|
|
|
|
|
|
it 'destroys the variable' do
|
2020-05-24 23:13:21 +05:30
|
|
|
expect { subject }.to change { variables_scope.count }.by(-1)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect { variable.reload }.to raise_error ActiveRecord::RecordNotFound
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a successful response' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has all variables in response' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to match_response_schema('variables')
|
|
|
|
end
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
context 'with missing variable' do
|
|
|
|
let(:variables_attributes) do
|
|
|
|
[variable_attributes.merge(_destroy: 'true', id: 'some-id')]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns not found response' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
context 'for variables of type file' do
|
|
|
|
let(:variables_attributes) do
|
|
|
|
[
|
|
|
|
new_variable_attributes.merge(variable_type: 'file')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates new variable of type file' do
|
2020-05-24 23:13:21 +05:30
|
|
|
expect { subject }.to change { file_variables_scope.count }.by(1)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|