Commit 3f52cee4 authored by Matija Čupić's avatar Matija Čupić

Add negative example with duplicate variable in spec

parent c241b9ed
......@@ -13,9 +13,23 @@ describe Projects::VariablesController do
end
describe 'PATCH #update' do
let!(:variable) { create(:ci_variable, project: project) }
let!(:variable) { create(:ci_variable, project: project, environment_scope: 'custom_scope') }
let(:owner) { project }
let(:variable_attributes) do
{ id: variable.id,
key: variable.key,
value: variable.value,
protected: variable.protected?.to_s,
environment_scope: variable.environment_scope }
end
let(:new_variable_attributes) do
{ key: 'new_key',
value: 'dummy_value',
protected: 'false',
environment_scope: 'new_scope' }
end
subject do
patch :update,
namespace_id: project.namespace.to_param,
......@@ -25,23 +39,10 @@ describe Projects::VariablesController do
end
context 'with same key and different environment scope' do
let(:variable_attributes) do
{ id: variable.id,
key: variable.key,
value: variable.value,
protected: variable.protected?.to_s,
environment_scope: variable.environment_scope }
end
let(:new_variable_attributes) do
{ key: variable.key,
value: 'dummy_value',
protected: 'false',
environment_scope: 'prod' }
end
let(:variables_attributes) do
[
variable_attributes,
new_variable_attributes
new_variable_attributes.merge(key: variable.key)
]
end
......@@ -65,5 +66,28 @@ describe Projects::VariablesController do
expect(response).to match_response_schema('variables')
end
end
context 'with same key and same environment scope' do
let(:variables_attributes) do
[
variable_attributes,
new_variable_attributes.merge(key: variable.key, environment_scope: variable.environment_scope)
]
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 { owner.variables.count }
end
it 'returns a bad request response' do
subject
expect(response).to have_gitlab_http_status(:bad_request)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment