Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
9a5ba5c6
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
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
4 deletions
+6
-4
app/validators/variable_duplicates_validator.rb
app/validators/variable_duplicates_validator.rb
+3
-1
spec/support/features/variable_list_shared_examples.rb
spec/support/features/variable_list_shared_examples.rb
+1
-1
spec/validators/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