summaryrefslogtreecommitdiff
path: root/spec/models/metrics
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/models/metrics
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
downloadgitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/models/metrics')
-rw-r--r--spec/models/metrics/dashboard/annotation_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/models/metrics/dashboard/annotation_spec.rb b/spec/models/metrics/dashboard/annotation_spec.rb
index f7fd7ded7e6..3cba31ffdfe 100644
--- a/spec/models/metrics/dashboard/annotation_spec.rb
+++ b/spec/models/metrics/dashboard/annotation_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
describe Metrics::Dashboard::Annotation do
+ using RSpec::Parameterized::TableSyntax
+
describe 'associations' do
it { is_expected.to belong_to(:environment).inverse_of(:metrics_dashboard_annotations) }
it { is_expected.to belong_to(:cluster).class_name('Clusters::Cluster').inverse_of(:metrics_dashboard_annotations) }
@@ -28,6 +30,26 @@ describe Metrics::Dashboard::Annotation do
end
end
+ context 'ending_at_after_starting_at' do
+ where(:starting_at, :ending_at, :valid?, :message) do
+ 2.days.ago.beginning_of_day | 1.day.ago.beginning_of_day | true | nil
+ 1.day.ago.beginning_of_day | nil | true | nil
+ 1.day.ago.beginning_of_day | 1.day.ago.beginning_of_day | true | nil
+ 1.day.ago.beginning_of_day | 2.days.ago.beginning_of_day | false | /Ending at can't be before starting_at time/
+ nil | 2.days.ago.beginning_of_day | false | /Starting at can't be blank/ # validation is covered by other method, be we need to assure, that ending_at_after_starting_at will not break with nil as starting_at
+ nil | nil | false | /Starting at can't be blank/ # validation is covered by other method, be we need to assure, that ending_at_after_starting_at will not break with nil as starting_at
+ end
+
+ with_them do
+ subject(:annotation) { build(:metrics_dashboard_annotation, starting_at: starting_at, ending_at: ending_at) }
+
+ it do
+ expect(annotation.valid?).to be(valid?)
+ expect(annotation.errors.full_messages).to include(message) if message
+ end
+ end
+ end
+
context 'environments annotation' do
subject { build(:metrics_dashboard_annotation) }
@@ -75,5 +97,16 @@ describe Metrics::Dashboard::Annotation do
expect(described_class.for_dashboard('other_dashboard.yml')).to match_array [other_dashboard_annotation]
end
end
+
+ describe '#ending_before' do
+ it 'returns annotations only for appointed dashboard' do
+ Timecop.freeze do
+ twelve_minutes_old_annotation = create(:metrics_dashboard_annotation, starting_at: 15.minutes.ago, ending_at: 12.minutes.ago)
+ create(:metrics_dashboard_annotation, starting_at: 15.minutes.ago, ending_at: 11.minutes.ago)
+
+ expect(described_class.ending_before(11.minutes.ago)).to match_array [fifteen_minutes_old_annotation, twelve_minutes_old_annotation]
+ end
+ end
+ end
end
end