summaryrefslogtreecommitdiff
path: root/spec/models/ci/freeze_period_spec.rb
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/models/ci/freeze_period_spec.rb
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
downloadgitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/models/ci/freeze_period_spec.rb')
-rw-r--r--spec/models/ci/freeze_period_spec.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/models/ci/freeze_period_spec.rb b/spec/models/ci/freeze_period_spec.rb
new file mode 100644
index 00000000000..f7f840c6696
--- /dev/null
+++ b/spec/models/ci/freeze_period_spec.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::FreezePeriod, type: :model do
+ subject { build(:ci_freeze_period) }
+
+ let(:invalid_cron) { '0 0 0 * *' }
+
+ it { is_expected.to belong_to(:project) }
+
+ it { is_expected.to respond_to(:freeze_start) }
+ it { is_expected.to respond_to(:freeze_end) }
+ it { is_expected.to respond_to(:cron_timezone) }
+
+ describe 'cron validations' do
+ it 'allows valid cron patterns' do
+ freeze_period = build(:ci_freeze_period)
+
+ expect(freeze_period).to be_valid
+ end
+
+ it 'does not allow invalid cron patterns on freeze_start' do
+ freeze_period = build(:ci_freeze_period, freeze_start: invalid_cron)
+
+ expect(freeze_period).not_to be_valid
+ end
+
+ it 'does not allow invalid cron patterns on freeze_end' do
+ freeze_period = build(:ci_freeze_period, freeze_end: invalid_cron)
+
+ expect(freeze_period).not_to be_valid
+ end
+
+ it 'does not allow an invalid timezone' do
+ freeze_period = build(:ci_freeze_period, cron_timezone: 'invalid')
+
+ expect(freeze_period).not_to be_valid
+ end
+
+ context 'when cron contains trailing whitespaces' do
+ it 'strips the attribute' do
+ freeze_period = build(:ci_freeze_period, freeze_start: ' 0 0 * * * ')
+
+ expect(freeze_period).to be_valid
+ expect(freeze_period.freeze_start).to eq('0 0 * * *')
+ end
+ end
+ end
+end