summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-02-13 19:46:02 +0100
committerMatija Čupić <matteeyah@gmail.com>2018-02-13 23:51:04 +0100
commit9a5ba5c67444d9b71597dd8c43955a055a047100 (patch)
tree166b3a5fa51aa62d081c91a39aa7580d56e44085
parenta4b843e9b844ed4e3a5f204e3fb5f43c68fd2db8 (diff)
downloadgitlab-ce-9a5ba5c67444d9b71597dd8c43955a055a047100.tar.gz
Add more information in variable_duplicates validator error message
-rw-r--r--app/validators/variable_duplicates_validator.rb4
-rw-r--r--spec/support/features/variable_list_shared_examples.rb2
-rw-r--r--spec/validators/variable_duplicates_validator_spec.rb4
3 files changed, 6 insertions, 4 deletions
diff --git a/app/validators/variable_duplicates_validator.rb b/app/validators/variable_duplicates_validator.rb
index 7887b217829..ae9ebdf28cf 100644
--- a/app/validators/variable_duplicates_validator.rb
+++ b/app/validators/variable_duplicates_validator.rb
@@ -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
diff --git a/spec/support/features/variable_list_shared_examples.rb b/spec/support/features/variable_list_shared_examples.rb
index 4315bf5d037..b7d896c9409 100644
--- a/spec/support/features/variable_list_shared_examples.rb
+++ b/spec/support/features/variable_list_shared_examples.rb
@@ -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
diff --git a/spec/validators/variable_duplicates_validator_spec.rb b/spec/validators/variable_duplicates_validator_spec.rb
index be80b901b88..0b71a67f94d 100644
--- a/spec/validators/variable_duplicates_validator_spec.rb
+++ b/spec/validators/variable_duplicates_validator_spec.rb
@@ -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