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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
c65529e8
Commit
c65529e8
authored
Feb 18, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Skip variables duplicates validator if variable is already a duplicate
parent
4319b15a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
1 deletion
+4
-1
app/models/group.rb
app/models/group.rb
+0
-1
app/validators/variable_duplicates_validator.rb
app/validators/variable_duplicates_validator.rb
+2
-0
spec/support/features/variable_list_shared_examples.rb
spec/support/features/variable_list_shared_examples.rb
+2
-0
No files found.
app/models/group.rb
View file @
c65529e8
...
@@ -37,7 +37,6 @@ class Group < Namespace
...
@@ -37,7 +37,6 @@ class Group < Namespace
validate
:visibility_level_allowed_by_sub_groups
validate
:visibility_level_allowed_by_sub_groups
validate
:visibility_level_allowed_by_parent
validate
:visibility_level_allowed_by_parent
validates
:variables
,
variable_duplicates:
true
validates
:variables
,
variable_duplicates:
true
validates_associated
:variables
,
if:
proc
{
|
group
|
group
.
errors
[
:variables
].
nil?
}
validates
:two_factor_grace_period
,
presence:
true
,
numericality:
{
greater_than_or_equal_to:
0
}
validates
:two_factor_grace_period
,
presence:
true
,
numericality:
{
greater_than_or_equal_to:
0
}
...
...
app/validators/variable_duplicates_validator.rb
View file @
c65529e8
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
# - Use `validates :xxx, uniqueness: { scope: :xxx_id }` in a child model
# - Use `validates :xxx, uniqueness: { scope: :xxx_id }` in a child model
class
VariableDuplicatesValidator
<
ActiveModel
::
EachValidator
class
VariableDuplicatesValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
def
validate_each
(
record
,
attribute
,
value
)
return
if
record
.
errors
.
include?
(
:"
#{
attribute
}
.key"
)
if
options
[
:scope
]
if
options
[
:scope
]
scoped
=
value
.
group_by
do
|
variable
|
scoped
=
value
.
group_by
do
|
variable
|
Array
(
options
[
:scope
]).
map
{
|
attr
|
variable
.
send
(
attr
)
}
# rubocop:disable GitlabSecurity/PublicSend
Array
(
options
[
:scope
]).
map
{
|
attr
|
variable
.
send
(
attr
)
}
# rubocop:disable GitlabSecurity/PublicSend
...
...
spec/support/features/variable_list_shared_examples.rb
View file @
c65529e8
...
@@ -261,6 +261,8 @@ shared_examples 'variable list' do
...
@@ -261,6 +261,8 @@ shared_examples 'variable list' do
click_button
(
'Save variables'
)
click_button
(
'Save variables'
)
wait_for_requests
wait_for_requests
expect
(
all
(
'.js-ci-variable-list-section .js-ci-variable-error-box ul li'
).
count
).
to
eq
(
1
)
# 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 have duplicate values \(.+\)/
)
expect
(
find
(
'.js-ci-variable-error-box'
)).
to
have_content
(
/Validation failed Variables have duplicate values \(.+\)/
)
...
...
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