diff options
author | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-04-04 19:14:49 +0900 |
---|---|---|
committer | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-04-06 23:46:59 +0900 |
commit | 4949e2b291bc59ee3855882a29df3bff9edfd4e5 (patch) | |
tree | 09bff0657878de147016b23ee7ce7f02d6cc24ea /app/validators | |
parent | 3d3df09713dcb70baceaeba7603fa49b89fc8007 (diff) | |
download | gitlab-ce-4949e2b291bc59ee3855882a29df3bff9edfd4e5.tar.gz |
Separate cron_valid? and cron_time_zone_valid?
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/cron_time_zone_validator.rb | 9 | ||||
-rw-r--r-- | app/validators/cron_validator.rb | 8 |
2 files changed, 10 insertions, 7 deletions
diff --git a/app/validators/cron_time_zone_validator.rb b/app/validators/cron_time_zone_validator.rb new file mode 100644 index 00000000000..9d4bbe1d458 --- /dev/null +++ b/app/validators/cron_time_zone_validator.rb @@ -0,0 +1,9 @@ +# 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 diff --git a/app/validators/cron_validator.rb b/app/validators/cron_validator.rb index 31eaa4147a5..cc07011d56b 100644 --- a/app/validators/cron_validator.rb +++ b/app/validators/cron_validator.rb @@ -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 |