Add more information in variable_duplicates validator error message
This commit is contained in:
parent
a4b843e9b8
commit
9a5ba5c674
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue