Skip variables duplicates validator if variable is already a duplicate
This commit is contained in:
parent
4319b15a78
commit
c65529e8f6
3 changed files with 4 additions and 1 deletions
|
@ -37,7 +37,6 @@ class Group < Namespace
|
|||
validate :visibility_level_allowed_by_sub_groups
|
||||
validate :visibility_level_allowed_by_parent
|
||||
validates :variables, variable_duplicates: true
|
||||
validates_associated :variables, if: proc { |group| group.errors[:variables].nil? }
|
||||
|
||||
validates :two_factor_grace_period, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
# - Use `validates :xxx, uniqueness: { scope: :xxx_id }` in a child model
|
||||
class VariableDuplicatesValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
return if record.errors.include?(:"#{attribute}.key")
|
||||
|
||||
if options[:scope]
|
||||
scoped = value.group_by do |variable|
|
||||
Array(options[:scope]).map { |attr| variable.send(attr) } # rubocop:disable GitlabSecurity/PublicSend
|
||||
|
|
|
@ -261,6 +261,8 @@ shared_examples 'variable list' do
|
|||
click_button('Save variables')
|
||||
wait_for_requests
|
||||
|
||||
expect(all('.js-ci-variable-list-section .js-ci-variable-error-box ul li').count).to eq(1)
|
||||
|
||||
# We check the first row because it re-sorts to alphabetical order on refresh
|
||||
page.within('.js-ci-variable-list-section') do
|
||||
expect(find('.js-ci-variable-error-box')).to have_content(/Validation failed Variables have duplicate values \(.+\)/)
|
||||
|
|
Loading…
Reference in a new issue