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
80bd2df4
Commit
80bd2df4
authored
Jan 06, 2021
by
Peter Leitzen
Committed by
Vitali Tatarintev
Jan 28, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate path being a list of strings
Checks whether the alert's field path is a list of strings
parent
db63248d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
5 deletions
+28
-5
ee/app/models/alert_management/alert_payload_field.rb
ee/app/models/alert_management/alert_payload_field.rb
+13
-2
ee/spec/factories/alert_management/alert_payload_fields.rb
ee/spec/factories/alert_management/alert_payload_fields.rb
+1
-1
ee/spec/models/alert_management/alert_payload_field_spec.rb
ee/spec/models/alert_management/alert_payload_field_spec.rb
+14
-2
No files found.
ee/app/models/alert_management/alert_payload_field.rb
View file @
80bd2df4
...
...
@@ -7,9 +7,20 @@ module AlertManagement
attr_accessor
:project
,
:path
,
:label
,
:type
SUPPORTED_TYPES
=
%w[string numeric datetime]
.
freeze
validates
:project
,
presence:
true
validates
:path
,
presence:
true
validates
:label
,
presence:
true
validates
:type
,
presence:
true
validates
:type
,
inclusion:
{
in:
SUPPORTED_TYPES
}
validate
:path_is_list_of_strings
private
def
path_is_list_of_strings
unless
path
.
is_a?
(
Array
)
&&
path
.
all?
{
|
segment
|
segment
.
is_a?
(
String
)
}
errors
.
add
(
:path
,
'must be a list of strings'
)
end
end
end
end
ee/spec/factories/alert_management/alert_payload_fields.rb
View file @
80bd2df4
...
...
@@ -3,7 +3,7 @@
FactoryBot
.
define
do
factory
:alert_management_alert_payload_field
,
class:
'AlertManagement::AlertPayloadField'
do
project
path
{
'title'
}
path
{
[
'title'
]
}
label
{
'Title'
}
type
{
'string'
}
end
...
...
ee/spec/models/alert_management/alert_payload_field_spec.rb
View file @
80bd2df4
...
...
@@ -3,10 +3,22 @@
require
'spec_helper'
RSpec
.
describe
AlertManagement
::
AlertPayloadField
do
let
(
:alert_payload_field
)
{
build_stubbed
(
:alert_management_alert_payload_field
)
}
describe
'Validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:path
)
}
it
{
is_expected
.
to
validate_presence_of
(
:label
)
}
it
{
is_expected
.
to
validate_presence_of
(
:type
)
}
it
{
is_expected
.
to
validate_inclusion_of
(
:type
).
in_array
(
described_class
::
SUPPORTED_TYPES
)
}
describe
'#path_is_list_of_strings'
do
before
do
alert_management_alert_payload_field
.
path
=
path
alert_management_alert_payload_field
.
valid?
end
context
'when path is nil'
context
'when path is empty array'
context
'when path does not contain only strings'
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