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
4949e2b2
Commit
4949e2b2
authored
Apr 04, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate cron_valid? and cron_time_zone_valid?
parent
3d3df097
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
25 deletions
+42
-25
app/models/ci/trigger_schedule.rb
app/models/ci/trigger_schedule.rb
+1
-1
app/validators/cron_time_zone_validator.rb
app/validators/cron_time_zone_validator.rb
+9
-0
app/validators/cron_validator.rb
app/validators/cron_validator.rb
+1
-7
lib/gitlab/ci/cron_parser.rb
lib/gitlab/ci/cron_parser.rb
+6
-4
spec/lib/gitlab/ci/cron_parser_spec.rb
spec/lib/gitlab/ci/cron_parser_spec.rb
+25
-13
No files found.
app/models/ci/trigger_schedule.rb
View file @
4949e2b2
...
...
@@ -12,7 +12,7 @@ module Ci
validates
:trigger
,
presence:
{
unless: :importing?
}
validates
:cron
,
cron:
true
,
presence:
{
unless: :importing?
}
validates
:cron_time_zone
,
presence:
{
unless: :importing?
}
validates
:cron_time_zone
,
cron_time_zone:
true
,
presence:
{
unless: :importing?
}
validates
:ref
,
presence:
{
unless: :importing?
}
after_create
:schedule_next_run!
...
...
app/validators/cron_time_zone_validator.rb
0 → 100644
View file @
4949e2b2
# CronTimeZoneValidator
#
# Custom validator for CronTimeZone.
class
CronTimeZoneValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
cron_parser
=
Gitlab
::
Ci
::
CronParser
.
new
(
record
.
cron
,
record
.
cron_time_zone
)
record
.
errors
.
add
(
attribute
,
" is invalid syntax"
)
unless
cron_parser
.
cron_time_zone_valid?
end
end
app/validators/cron_validator.rb
View file @
4949e2b2
...
...
@@ -4,12 +4,6 @@
class
CronValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
cron_parser
=
Gitlab
::
Ci
::
CronParser
.
new
(
record
.
cron
,
record
.
cron_time_zone
)
is_valid_cron
,
is_valid_cron_time_zone
=
cron_parser
.
validation
if
!
is_valid_cron
record
.
errors
.
add
(
:cron
,
" is invalid syntax"
)
elsif
!
is_valid_cron_time_zone
record
.
errors
.
add
(
:cron_time_zone
,
" is invalid timezone"
)
end
record
.
errors
.
add
(
attribute
,
" is invalid syntax"
)
unless
cron_parser
.
cron_valid?
end
end
lib/gitlab/ci/cron_parser.rb
View file @
4949e2b2
...
...
@@ -14,10 +14,12 @@ module Gitlab
cron_line
.
next_time
(
time
).
in_time_zone
(
Time
.
zone
)
if
cron_line
.
present?
end
def
validation
is_valid_cron
=
try_parse_cron
(
@cron
,
VALID_SYNTAX_SAMPLE_TIME_ZONE
).
present?
is_valid_cron_time_zone
=
try_parse_cron
(
VALID_SYNTAX_SAMPLE_CRON
,
@cron_time_zone
).
present?
return
is_valid_cron
,
is_valid_cron_time_zone
def
cron_valid?
try_parse_cron
(
@cron
,
VALID_SYNTAX_SAMPLE_TIME_ZONE
).
present?
end
def
cron_time_zone_valid?
try_parse_cron
(
VALID_SYNTAX_SAMPLE_CRON
,
@cron_time_zone
).
present?
end
private
...
...
spec/lib/gitlab/ci/cron_parser_spec.rb
View file @
4949e2b2
...
...
@@ -82,23 +82,35 @@ describe Gitlab::Ci::CronParser do
end
end
describe
'#validation'
do
it
'returns results'
do
is_valid_cron
,
is_valid_cron_time_zone
=
described_class
.
new
(
'* * * * *'
,
'Europe/Istanbul'
).
validation
expect
(
is_valid_cron
).
to
eq
(
true
)
expect
(
is_valid_cron_time_zone
).
to
eq
(
true
)
describe
'#cron_valid?'
do
subject
{
described_class
.
new
(
cron
,
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
).
cron_valid?
}
context
'when cron is valid'
do
let
(
:cron
)
{
'* * * * *'
}
it
{
is_expected
.
to
eq
(
true
)
}
end
it
'returns results
'
do
is_valid_cron
,
is_valid_cron_time_zone
=
described_class
.
new
(
'*********'
,
'Europe/Istanbul'
).
validation
expect
(
is_valid_cron
).
to
eq
(
false
)
expect
(
is_valid_cron_time_zone
).
to
eq
(
true
)
context
'when cron is invalid
'
do
let
(
:cron
)
{
'*********'
}
it
{
is_expected
.
to
eq
(
false
)
}
end
end
describe
'#cron_time_zone_valid?'
do
subject
{
described_class
.
new
(
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_CRON
,
cron_time_zone
).
cron_time_zone_valid?
}
context
'when cron is valid'
do
let
(
:cron_time_zone
)
{
'Europe/Istanbul'
}
it
{
is_expected
.
to
eq
(
true
)
}
end
context
'when cron is invalid'
do
let
(
:cron_time_zone
)
{
'Invalid-zone'
}
it
'returns results'
do
is_valid_cron
,
is_valid_cron_time_zone
=
described_class
.
new
(
'* * * * *'
,
'Invalid-zone'
).
validation
expect
(
is_valid_cron
).
to
eq
(
true
)
expect
(
is_valid_cron_time_zone
).
to
eq
(
false
)
it
{
is_expected
.
to
eq
(
false
)
}
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