summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2019-05-07 07:16:00 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2019-05-07 07:16:00 +0000
commitb3490d516c710b26f0b33e68ed0046c8dd8564e0 (patch)
tree3fb5833a8108da3363a5f087212169a992cd065b
parent3371c1cb7102ec557065ea7e92b9f6fff9744bd1 (diff)
parent2fcf80de3f153c928245446460daf2bf6bdfa7f1 (diff)
downloadgitlab-ce-b3490d516c710b26f0b33e68ed0046c8dd8564e0.tar.gz
Merge branch 'strip-attr-cron-in-pipeline-schedule' into 'master'
Strip whitespace for PipelineSchedule#cron See merge request gitlab-org/gitlab-ce!27990
-rw-r--r--app/models/ci/pipeline_schedule.rb3
-rw-r--r--spec/models/ci/pipeline_schedule_spec.rb9
2 files changed, 12 insertions, 0 deletions
diff --git a/app/models/ci/pipeline_schedule.rb b/app/models/ci/pipeline_schedule.rb
index 1454b2dfb39..c0a0ca9acf6 100644
--- a/app/models/ci/pipeline_schedule.rb
+++ b/app/models/ci/pipeline_schedule.rb
@@ -5,6 +5,7 @@ module Ci
extend Gitlab::Ci::Model
include Importable
include IgnorableColumn
+ include StripAttribute
ignore_column :deleted_at
@@ -22,6 +23,8 @@ module Ci
before_save :set_next_run_at
+ strip_attributes :cron
+
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb
index 81913f4a3b6..1bfc14d2839 100644
--- a/spec/models/ci/pipeline_schedule_spec.rb
+++ b/spec/models/ci/pipeline_schedule_spec.rb
@@ -35,6 +35,15 @@ describe Ci::PipelineSchedule do
expect(pipeline_schedule).not_to be_valid
end
end
+
+ context 'when cron contains trailing whitespaces' do
+ it 'strips the attribute' do
+ pipeline_schedule = build(:ci_pipeline_schedule, cron: ' 0 0 * * * ')
+
+ expect(pipeline_schedule).to be_valid
+ expect(pipeline_schedule.cron).to eq('0 0 * * *')
+ end
+ end
end
describe '#set_next_run_at' do