diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/models/ci/freeze_period_status_spec.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/models/ci/freeze_period_status_spec.rb')
-rw-r--r-- | spec/models/ci/freeze_period_status_spec.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/models/ci/freeze_period_status_spec.rb b/spec/models/ci/freeze_period_status_spec.rb new file mode 100644 index 00000000000..b700ec8c45f --- /dev/null +++ b/spec/models/ci/freeze_period_status_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe Ci::FreezePeriodStatus do + let(:project) { create :project } + # '0 23 * * 5' == "At 23:00 on Friday."", '0 7 * * 1' == "At 07:00 on Monday."" + let(:friday_2300) { '0 23 * * 5' } + let(:monday_0700) { '0 7 * * 1' } + + subject { described_class.new(project: project).execute } + + shared_examples 'within freeze period' do |time| + it 'is frozen' do + Timecop.freeze(time) do + expect(subject).to be_truthy + end + end + end + + shared_examples 'outside freeze period' do |time| + it 'is not frozen' do + Timecop.freeze(time) do + expect(subject).to be_falsy + end + end + end + + describe 'single freeze period' do + let!(:freeze_period) { create(:ci_freeze_period, project: project, freeze_start: friday_2300, freeze_end: monday_0700) } + + it_behaves_like 'outside freeze period', Time.utc(2020, 4, 10, 22, 59) + + it_behaves_like 'within freeze period', Time.utc(2020, 4, 10, 23, 1) + + it_behaves_like 'within freeze period', Time.utc(2020, 4, 13, 6, 59) + + it_behaves_like 'outside freeze period', Time.utc(2020, 4, 13, 7, 1) + end + + describe 'multiple freeze periods' do + # '30 23 * * 5' == "At 23:30 on Friday."", '0 8 * * 1' == "At 08:00 on Monday."" + let(:friday_2330) { '30 23 * * 5' } + let(:monday_0800) { '0 8 * * 1' } + + let!(:freeze_period_1) { create(:ci_freeze_period, project: project, freeze_start: friday_2300, freeze_end: monday_0700) } + let!(:freeze_period_2) { create(:ci_freeze_period, project: project, freeze_start: friday_2330, freeze_end: monday_0800) } + + it_behaves_like 'outside freeze period', Time.utc(2020, 4, 10, 22, 59) + + it_behaves_like 'within freeze period', Time.utc(2020, 4, 10, 23, 29) + + it_behaves_like 'within freeze period', Time.utc(2020, 4, 11, 10, 0) + + it_behaves_like 'within freeze period', Time.utc(2020, 4, 10, 23, 1) + + it_behaves_like 'within freeze period', Time.utc(2020, 4, 13, 6, 59) + + it_behaves_like 'within freeze period', Time.utc(2020, 4, 13, 7, 59) + + it_behaves_like 'outside freeze period', Time.utc(2020, 4, 13, 8, 1) + end +end |