Fix validation of duplicate new variables
This commit is contained in:
parent
f7ed096455
commit
79570ce24f
|
@ -36,6 +36,7 @@ class Group < Namespace
|
|||
validate :visibility_level_allowed_by_projects
|
||||
validate :visibility_level_allowed_by_sub_groups
|
||||
validate :visibility_level_allowed_by_parent
|
||||
validates :variables, variable_duplicates: true
|
||||
|
||||
validates :two_factor_grace_period, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
|
||||
|
|
|
@ -261,6 +261,7 @@ class Project < ActiveRecord::Base
|
|||
validates :repository_storage,
|
||||
presence: true,
|
||||
inclusion: { in: ->(_object) { Gitlab.config.repositories.storages.keys } }
|
||||
validates :variables, variable_duplicates: true
|
||||
|
||||
has_many :uploads, as: :model, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
||||
|
||||
|
|
|
@ -48,6 +48,29 @@ shared_examples 'PATCH #update updates variables' do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with duplicate new variable parameters' do
|
||||
let(:variables_attributes) do
|
||||
[
|
||||
new_variable_attributes,
|
||||
new_variable_attributes.merge(value: 'other_value')
|
||||
]
|
||||
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
|
||||
|
||||
context 'with valid new variable parameters' do
|
||||
let(:variables_attributes) do
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue