Add more information in variable_duplicates validator error message

This commit is contained in:
Matija Čupić 2018-02-13 19:46:02 +01:00
parent a4b843e9b8
commit 9a5ba5c674
No known key found for this signature in database
GPG Key ID: 4BAF84FFACD2E5DE
3 changed files with 6 additions and 4 deletions

View File

@ -20,7 +20,9 @@ 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?
record.errors.add(attribute, "Duplicate variables: #{duplicates.join(", ")}")
error_message = "has duplicate variables (#{duplicates.join(", ")})"
error_message += " in #{options[:scope]} scope" if options[:scope]
record.errors.add(attribute, error_message)
end
end
end

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 Duplicate variables: samekey')
expect(find('.js-ci-variable-error-box')).to have_content(/Validation failed Variables has duplicate variables \(.+\)/)
end
end
end

View File

@ -30,7 +30,7 @@ describe VariableDuplicatesValidator do
it 'has a duplicate key error' do
subject
expect(project.errors[:variables]).to include("Duplicate variables: #{project.variables.last.key}")
expect(project.errors).to have_key(:variables)
end
end
end
@ -59,7 +59,7 @@ describe VariableDuplicatesValidator do
it 'has a duplicate key error' do
subject
expect(project.errors[:variables]).to include("Duplicate variables: #{project.variables.last.key}")
expect(project.errors).to have_key(:variables)
end
end
end