2017-02-02 17:25:12 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::VariablesController do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2017-02-02 17:25:12 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_master(user)
|
2017-02-02 17:25:12 +00:00
|
|
|
end
|
|
|
|
|
2018-01-12 21:39:42 +00:00
|
|
|
describe 'POST #save_multiple' do
|
2018-01-13 00:46:43 +00:00
|
|
|
let(:variable) { create(:ci_variable) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.variables << variable
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid new variable parameters' do
|
|
|
|
subject do
|
|
|
|
post :save_multiple,
|
|
|
|
namespace_id: project.namespace.to_param, project_id: project,
|
2018-01-23 18:53:29 +00:00
|
|
|
variables_attributes: [{ id: variable.id, key: variable.key,
|
|
|
|
value: 'other_value',
|
|
|
|
protected: variable.protected?.to_s },
|
|
|
|
{ key: '..?', value: 'dummy_value',
|
|
|
|
protected: 'false' }],
|
2018-01-13 00:46:43 +00:00
|
|
|
format: :json
|
|
|
|
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
|
|
|
|
subject do
|
|
|
|
post :save_multiple,
|
|
|
|
namespace_id: project.namespace.to_param, project_id: project,
|
2018-01-23 18:53:29 +00:00
|
|
|
variables_attributes: [{ id: variable.id, key: variable.key,
|
|
|
|
value: 'other_value',
|
|
|
|
protected: variable.protected?.to_s },
|
|
|
|
{ key: 'new_key', value: 'dummy_value',
|
|
|
|
protected: 'false' }],
|
2018-01-13 00:46:43 +00:00
|
|
|
format: :json
|
|
|
|
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-12 21:39:42 +00:00
|
|
|
end
|
2018-01-13 02:36:04 +00:00
|
|
|
|
|
|
|
context 'with a deleted variable' do
|
|
|
|
subject do
|
|
|
|
post :save_multiple,
|
|
|
|
namespace_id: project.namespace.to_param, project_id: project,
|
2018-01-23 00:17:40 +00:00
|
|
|
variables_attributes: [{ id: variable.id, key: variable.key,
|
2018-01-23 18:53:29 +00:00
|
|
|
value: variable.value,
|
|
|
|
protected: variable.protected?.to_s,
|
|
|
|
_destroy: 'true' }],
|
2018-01-13 02:36:04 +00:00
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
2018-01-12 21:39:42 +00:00
|
|
|
end
|
2017-02-02 17:25:12 +00:00
|
|
|
end
|