Improve validation message and add changelog

This commit is contained in:
Kamil Trzciński 2018-02-14 22:51:04 +01:00
parent 48db60e479
commit 84c14ac0c2
3 changed files with 7 additions and 2 deletions

View File

@ -20,7 +20,7 @@ class VariableDuplicatesValidator < ActiveModel::EachValidator
def validate_duplicates(record, attribute, values)
duplicates = values.reject(&:marked_for_destruction?).group_by(&:key).select { |_, v| v.many? }.map(&:first)
if duplicates.any?
error_message = "has duplicate variables (#{duplicates.join(", ")})"
error_message = "have duplicate values (#{duplicates.join(", ")})"
error_message += " for #{values.first.send(options[:scope])} scope" if options[:scope] # rubocop:disable GitlabSecurity/PublicSend
record.errors.add(attribute, error_message)
end

View File

@ -0,0 +1,5 @@
---
title: Fix validation of environment scope of variables
merge_request:
author:
type: fixed

View File

@ -263,7 +263,7 @@ shared_examples 'variable list' do
# 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 has duplicate variables \(.+\)/)
expect(find('.js-ci-variable-error-box')).to have_content(/Validation failed Variables have duplicate values \(.+\)/)
end
end
end