summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 18:09:19 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 18:09:19 +0000
commit3290d46655f07d7ae3dca788d6df9f326972ffd8 (patch)
tree0d24713e1592cdd3583257f14a52d46a22539ed1 /spec/models
parentc6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf (diff)
downloadgitlab-ce-3290d46655f07d7ae3dca788d6df9f326972ffd8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/clusters/cluster_spec.rb1
-rw-r--r--spec/models/environment_spec.rb1
-rw-r--r--spec/models/metrics/dashboard/annotation_spec.rb53
3 files changed, 55 insertions, 0 deletions
diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb
index f6c19ccc9d3..8685838fdde 100644
--- a/spec/models/clusters/cluster_spec.rb
+++ b/spec/models/clusters/cluster_spec.rb
@@ -27,6 +27,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
it { is_expected.to have_many(:kubernetes_namespaces) }
it { is_expected.to have_one(:cluster_project) }
it { is_expected.to have_many(:deployment_clusters) }
+ it { is_expected.to have_many(:metrics_dashboard_annotations) }
it { is_expected.to delegate_method(:status).to(:provider) }
it { is_expected.to delegate_method(:status_reason).to(:provider) }
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 896203d8669..d0305d878e3 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -17,6 +17,7 @@ describe Environment, :use_clean_rails_memory_store_caching do
it { is_expected.to belong_to(:project).required }
it { is_expected.to have_many(:deployments) }
+ it { is_expected.to have_many(:metrics_dashboard_annotations) }
it { is_expected.to delegate_method(:stop_action).to(:last_deployment) }
it { is_expected.to delegate_method(:manual_actions).to(:last_deployment) }
diff --git a/spec/models/metrics/dashboard/annotation_spec.rb b/spec/models/metrics/dashboard/annotation_spec.rb
new file mode 100644
index 00000000000..ed3bef37a7c
--- /dev/null
+++ b/spec/models/metrics/dashboard/annotation_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Metrics::Dashboard::Annotation do
+ 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) }
+ end
+
+ describe 'validation' do
+ it { is_expected.to validate_presence_of(:description) }
+ it { is_expected.to validate_presence_of(:dashboard_path) }
+ it { is_expected.to validate_presence_of(:starting_at) }
+ it { is_expected.to validate_length_of(:dashboard_path).is_at_most(255) }
+ it { is_expected.to validate_length_of(:panel_xid).is_at_most(255) }
+ it { is_expected.to validate_length_of(:description).is_at_most(255) }
+
+ context 'orphaned annotation' do
+ subject { build(:metrics_dashboard_annotation, environment: nil) }
+
+ it { is_expected.not_to be_valid }
+
+ it 'reports error about both missing relations' do
+ subject.valid?
+
+ expect(subject.errors.full_messages).to include(/Annotation must belong to a cluster or an environment/)
+ end
+ end
+
+ context 'environments annotation' do
+ subject { build(:metrics_dashboard_annotation) }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'clusters annotation' do
+ subject { build(:metrics_dashboard_annotation, :with_cluster) }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'annotation with shared ownership' do
+ subject { build(:metrics_dashboard_annotation, :with_cluster, environment: build(:environment) ) }
+
+ it 'reports error about both shared ownership' do
+ subject.valid?
+
+ expect(subject.errors.full_messages).to include(/Annotation can't belong to both a cluster and an environment at the same time/)
+ end
+ end
+ end
+end