2017-05-03 18:51:55 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Groups::VariablesController do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
group.add_master(user)
|
|
|
|
end
|
|
|
|
|
2018-01-29 17:54:16 +00:00
|
|
|
describe 'GET #show' do
|
|
|
|
let!(:variable) { create(:ci_group_variable, group: group) }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
get :show, group_id: group, format: :json
|
|
|
|
end
|
|
|
|
|
2018-01-29 18:01:21 +00:00
|
|
|
it 'renders the ci_group_variable as json' do
|
2018-01-29 17:54:16 +00:00
|
|
|
subject
|
|
|
|
|
2018-02-01 21:35:00 +00:00
|
|
|
expect(response).to match_response_schema('variables')
|
2018-01-29 17:54:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #update' do
|
2018-01-23 18:24:55 +00:00
|
|
|
let!(:variable) { create(:ci_group_variable, group: group) }
|
2018-02-01 20:58:05 +00:00
|
|
|
let(:variable_attributes) do
|
|
|
|
{ id: variable.id, key: variable.key,
|
|
|
|
value: variable.value,
|
|
|
|
protected: variable.protected?.to_s }
|
|
|
|
end
|
|
|
|
let(:new_variable_attributes) do
|
|
|
|
{ key: 'new_key', value: 'dummy_value',
|
|
|
|
protected: 'false' }
|
|
|
|
end
|
2018-01-23 18:24:55 +00:00
|
|
|
|
|
|
|
context 'with invalid new variable parameters' do
|
|
|
|
subject do
|
2018-01-29 23:29:13 +00:00
|
|
|
patch :update,
|
2018-01-23 18:24:55 +00:00
|
|
|
group_id: group,
|
2018-02-01 20:58:05 +00:00
|
|
|
variables_attributes: [variable_attributes.merge(value: 'other_value'),
|
|
|
|
new_variable_attributes.merge(key: '..?')],
|
2018-01-23 18:24:55 +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 { group.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
|
2018-01-29 23:29:13 +00:00
|
|
|
patch :update,
|
2018-01-23 18:24:55 +00:00
|
|
|
group_id: group,
|
2018-02-01 20:58:05 +00:00
|
|
|
variables_attributes: [variable_attributes.merge(value: 'other_value'),
|
|
|
|
new_variable_attributes],
|
2018-01-23 18:24:55 +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 { group.variables.count }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a successful response' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
2018-01-29 23:44:53 +00:00
|
|
|
|
|
|
|
it 'has all variables in response' do
|
|
|
|
subject
|
|
|
|
|
2018-02-01 21:35:00 +00:00
|
|
|
expect(response).to match_response_schema('variables')
|
2018-01-29 23:44:53 +00:00
|
|
|
end
|
2018-01-23 18:24:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a deleted variable' do
|
|
|
|
subject do
|
2018-01-29 23:29:13 +00:00
|
|
|
patch :update,
|
2018-01-23 18:24:55 +00:00
|
|
|
group_id: group,
|
2018-02-01 20:58:05 +00:00
|
|
|
variables_attributes: [variable_attributes.merge(_destroy: 'true')],
|
2018-01-23 18:24:55 +00:00
|
|
|
format: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'destroys the variable' do
|
|
|
|
expect { subject }.to change { group.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 23:44:53 +00:00
|
|
|
|
|
|
|
it 'has all variables in response' do
|
|
|
|
subject
|
|
|
|
|
2018-02-01 21:35:00 +00:00
|
|
|
expect(response).to match_response_schema('variables')
|
2018-01-29 23:44:53 +00:00
|
|
|
end
|
2018-01-23 18:24:55 +00:00
|
|
|
end
|
|
|
|
end
|
2017-05-03 18:51:55 +00:00
|
|
|
end
|