summaryrefslogtreecommitdiff
path: root/spec/validators
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /spec/validators
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
downloadgitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/validators')
-rw-r--r--spec/validators/cron_freeze_period_timezone_validator_spec.rb24
-rw-r--r--spec/validators/cron_validator_spec.rb47
2 files changed, 71 insertions, 0 deletions
diff --git a/spec/validators/cron_freeze_period_timezone_validator_spec.rb b/spec/validators/cron_freeze_period_timezone_validator_spec.rb
new file mode 100644
index 00000000000..d283b89fa54
--- /dev/null
+++ b/spec/validators/cron_freeze_period_timezone_validator_spec.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe CronFreezePeriodTimezoneValidator do
+ using RSpec::Parameterized::TableSyntax
+
+ subject { create :ci_freeze_period }
+
+ where(:freeze_start, :freeze_end, :is_valid) do
+ '0 23 * * 5' | '0 7 * * 1' | true
+ '0 23 * * 5' | 'invalid' | false
+ 'invalid' | '0 7 * * 1' | false
+ end
+
+ with_them do
+ it 'crontab validation' do
+ subject.freeze_start = freeze_start
+ subject.freeze_end = freeze_end
+
+ expect(subject.valid?).to eq(is_valid)
+ end
+ end
+end
diff --git a/spec/validators/cron_validator_spec.rb b/spec/validators/cron_validator_spec.rb
new file mode 100644
index 00000000000..d6605610402
--- /dev/null
+++ b/spec/validators/cron_validator_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe CronValidator do
+ subject do
+ Class.new do
+ include ActiveModel::Model
+ include ActiveModel::Validations
+ attr_accessor :cron
+ validates :cron, cron: true
+
+ def cron_timezone
+ 'UTC'
+ end
+ end.new
+ end
+
+ it 'validates valid crontab' do
+ subject.cron = '0 23 * * 5'
+
+ expect(subject.valid?).to be_truthy
+ end
+
+ it 'validates invalid crontab' do
+ subject.cron = 'not a cron'
+
+ expect(subject.valid?).to be_falsy
+ end
+
+ context 'cron field is not whitelisted' do
+ subject do
+ Class.new do
+ include ActiveModel::Model
+ include ActiveModel::Validations
+ attr_accessor :cron_partytime
+ validates :cron_partytime, cron: true
+ end.new
+ end
+
+ it 'raises an error' do
+ subject.cron_partytime = '0 23 * * 5'
+
+ expect { subject.valid? }.to raise_error(StandardError, "Non-whitelisted attribute")
+ end
+ end
+end