Commit 9a5ba5c6 authored by Matija Čupić's avatar Matija Čupić

Add more information in variable_duplicates validator error message

parent a4b843e9
...@@ -20,7 +20,9 @@ class VariableDuplicatesValidator < ActiveModel::EachValidator ...@@ -20,7 +20,9 @@ class VariableDuplicatesValidator < ActiveModel::EachValidator
def validate_duplicates(record, attribute, values) def validate_duplicates(record, attribute, values)
duplicates = values.reject(&:marked_for_destruction?).group_by(&:key).select { |_, v| v.many? }.map(&:first) duplicates = values.reject(&:marked_for_destruction?).group_by(&:key).select { |_, v| v.many? }.map(&:first)
if duplicates.any? 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 end
end end
...@@ -263,7 +263,7 @@ shared_examples 'variable list' do ...@@ -263,7 +263,7 @@ shared_examples 'variable list' do
# We check the first row because it re-sorts to alphabetical order on refresh # We check the first row because it re-sorts to alphabetical order on refresh
page.within('.js-ci-variable-list-section') do 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 end
end end
...@@ -30,7 +30,7 @@ describe VariableDuplicatesValidator do ...@@ -30,7 +30,7 @@ describe VariableDuplicatesValidator do
it 'has a duplicate key error' do it 'has a duplicate key error' do
subject subject
expect(project.errors[:variables]).to include("Duplicate variables: #{project.variables.last.key}") expect(project.errors).to have_key(:variables)
end end
end end
end end
...@@ -59,7 +59,7 @@ describe VariableDuplicatesValidator do ...@@ -59,7 +59,7 @@ describe VariableDuplicatesValidator do
it 'has a duplicate key error' do it 'has a duplicate key error' do
subject subject
expect(project.errors[:variables]).to include("Duplicate variables: #{project.variables.last.key}") expect(project.errors).to have_key(:variables)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment