BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
9a5ba5c6
Unverified
Commit
9a5ba5c6
authored
Feb 13, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more information in variable_duplicates validator error message
parent
a4b843e9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
4 deletions
+6
-4
variable_duplicates_validator.rb
app/validators/variable_duplicates_validator.rb
+3
-1
variable_list_shared_examples.rb
spec/support/features/variable_list_shared_examples.rb
+1
-1
variable_duplicates_validator_spec.rb
spec/validators/variable_duplicates_validator_spec.rb
+2
-2
No files found.
app/validators/variable_duplicates_validator.rb
View file @
9a5ba5c6
...
...
@@ -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
spec/support/features/variable_list_shared_examples.rb
View file @
9a5ba5c6
...
...
@@ -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
spec/validators/variable_duplicates_validator_spec.rb
View file @
9a5ba5c6
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment