summaryrefslogtreecommitdiff
path: root/spec/controllers
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-01-23 19:24:55 +0100
committerMatija Čupić <matteeyah@gmail.com>2018-02-05 18:58:17 +0100
commitcc2bed9283039db726f42184ea635f057534205f (patch)
treefaee9281088f8975c60edd4650c614cf319d05dc /spec/controllers
parentedbe911b04465f0e6c72e102d083d0e85848a552 (diff)
downloadgitlab-ce-cc2bed9283039db726f42184ea635f057534205f.tar.gz
Port #save_multiple to Groups::VariablesController
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/groups/variables_controller_spec.rb79
1 files changed, 74 insertions, 5 deletions
diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb
index 8ea98cd9e8f..294e712f45d 100644
--- a/spec/controllers/groups/variables_controller_spec.rb
+++ b/spec/controllers/groups/variables_controller_spec.rb
@@ -29,13 +29,9 @@ describe Groups::VariablesController do
end
describe 'POST #update' do
- let(:variable) { create(:ci_group_variable) }
+ let!(:variable) { create(:ci_group_variable, group: group) }
context 'updating a variable with valid characters' do
- before do
- group.variables << variable
- end
-
it 'shows a success flash message' do
post :update, group_id: group,
id: variable.id, variable: { key: variable.key, value: 'two' }
@@ -53,4 +49,77 @@ describe Groups::VariablesController do
end
end
end
+
+ describe 'POST #save_multiple' do
+ let!(:variable) { create(:ci_group_variable, group: group) }
+
+ context 'with invalid new variable parameters' do
+ subject do
+ post :save_multiple,
+ group_id: group,
+ variables_attributes: [{ id: variable.id, 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 { 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
+ post :save_multiple,
+ group_id: group,
+ variables_attributes: [{ id: variable.id, 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 { group.variables.count }.by(1)
+ end
+
+ it 'returns a successful response' do
+ subject
+
+ expect(response).to have_gitlab_http_status(:ok)
+ end
+ end
+
+ context 'with a deleted variable' do
+ subject do
+ post :save_multiple,
+ group_id: group,
+ variables_attributes: [{ id: variable.id, key: variable.key,
+ value: variable.value, _destroy: 'true' }],
+ 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
+ end
+ end
end