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)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_master(user)
|
2017-02-02 12:25:12 -05:00
|
|
|
end
|
|
|
|
|
2018-01-29 12:39:06 -05:00
|
|
|
describe 'GET #show' do
|
|
|
|
let(:variable) { create(:ci_variable) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.variables << variable
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
2018-02-02 12:54:13 -05:00
|
|
|
get :show, namespace_id: project.namespace.to_param, project_id: project, format: :json
|
2018-01-29 12:39:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the ci_variable as json' do
|
|
|
|
subject
|
|
|
|
|
2018-02-01 16:35:00 -05:00
|
|
|
expect(response).to match_response_schema('variables')
|
2018-01-29 12:39:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #update' do
|
2018-01-12 19:46:43 -05:00
|
|
|
let(:variable) { create(:ci_variable) }
|
2018-02-02 12:54:13 -05:00
|
|
|
|
|
|
|
subject do
|
|
|
|
patch :update,
|
|
|
|
namespace_id: project.namespace.to_param, project_id: project,
|
|
|
|
variables_attributes: variables_attributes,
|
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
|
2018-02-01 15:58:05 -05:00
|
|
|
let(:variable_attributes) do
|
2018-02-02 12:54:13 -05:00
|
|
|
{ id: variable.id,
|
|
|
|
key: variable.key,
|
2018-02-01 15:58:05 -05:00
|
|
|
value: variable.value,
|
|
|
|
protected: variable.protected?.to_s }
|
|
|
|
end
|
|
|
|
let(:new_variable_attributes) do
|
2018-02-02 12:54:13 -05:00
|
|
|
{ key: 'new_key',
|
|
|
|
value: 'dummy_value',
|
2018-02-01 15:58:05 -05:00
|
|
|
protected: 'false' }
|
|
|
|
end
|
2018-01-12 19:46:43 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.variables << variable
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid new variable parameters' do
|
2018-02-02 12:54:13 -05:00
|
|
|
let(:variables_attributes) do
|
|
|
|
[
|
|
|
|
variable_attributes.merge(value: 'other_value'),
|
|
|
|
new_variable_attributes.merge(key: '...?')
|
|
|
|
]
|
2018-01-12 19:46:43 -05:00
|
|
|
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 { project.variables.count }
|
|
|
|
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
|
2018-02-02 12:54:13 -05:00
|
|
|
let(:variables_attributes) do
|
|
|
|
[
|
|
|
|
variable_attributes.merge(value: 'other_value'),
|
|
|
|
new_variable_attributes
|
|
|
|
]
|
2018-01-12 19:46:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the existing variable' do
|
|
|
|
expect { subject }.to change { variable.reload.value }.to('other_value')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the new variable' do
|
|
|
|
expect { subject }.to change { project.variables.count }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a successful response' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
2018-01-29 18:44:53 -05:00
|
|
|
|
|
|
|
it 'has all variables in response' do
|
|
|
|
subject
|
|
|
|
|
2018-02-01 16:35:00 -05:00
|
|
|
expect(response).to match_response_schema('variables')
|
2018-01-29 18:44:53 -05:00
|
|
|
end
|
2018-01-12 16:39:42 -05:00
|
|
|
end
|
2018-01-12 21:36:04 -05:00
|
|
|
|
|
|
|
context 'with a deleted variable' do
|
2018-02-02 12:54:13 -05:00
|
|
|
let(:variables_attributes) { [variable_attributes.merge(_destroy: 'true')] }
|
2018-01-12 21:36:04 -05:00
|
|
|
|
|
|
|
it 'destroys the variable' do
|
|
|
|
expect { subject }.to change { project.variables.count }.by(-1)
|
|
|
|
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
|
2018-01-29 18:44:53 -05:00
|
|
|
|
|
|
|
it 'has all variables in response' do
|
|
|
|
subject
|
|
|
|
|
2018-02-01 16:35:00 -05:00
|
|
|
expect(response).to match_response_schema('variables')
|
2018-01-29 18:44:53 -05:00
|
|
|
end
|
2018-01-12 21:36:04 -05:00
|
|
|
end
|
2018-01-12 16:39:42 -05:00
|
|
|
end
|
2017-02-02 12:25:12 -05:00
|
|
|
end
|