diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-01-13 03:46:43 +0300 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-02-05 20:57:42 +0300 |
commit | 121d84d774e18b27a8a4624f173e97cfad0d7f7c (patch) | |
tree | 21f9a7c0d493cbb09215b630c04363a31cd2c1a5 /spec/controllers/projects | |
parent | fe96a1f268558526fd122a348866fbf513ac17e2 (diff) |
Implement multiple variable handling action
Diffstat (limited to 'spec/controllers/projects')
-rw-r--r-- | spec/controllers/projects/variables_controller_spec.rb | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 97284909b3c..e0294fd4a46 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -57,9 +57,58 @@ describe Projects::VariablesController do end describe 'POST #save_multiple' do - it 'returns a successful response' do - post :save_multiple, namespace_id: project.namespace.to_param, project_id: project - expect(response).to have_gitlab_http_status(:ok) + 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, + variables: [{ key: variable.key, value: 'other_value' }, + { key: '..?', value: 'dummy_value' }], + 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, + variables: [{ key: variable.key, value: 'other_value' }, + { key: 'new_key', value: 'dummy_value' }], + 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 end end end |