summaryrefslogtreecommitdiff
path: root/app/models/prometheus_metric.rb
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-09-04 11:50:58 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2018-09-04 12:19:23 +0200
commit5646f3f551fe133ff0726af00d435fab2509f1e5 (patch)
tree7ff5c0ec17b0b1d0140a875bfc7a8ba5147ea33f /app/models/prometheus_metric.rb
parente6d2465d9732dea7b69e498c7a1feed544ba6a3c (diff)
downloadgitlab-ce-5646f3f551fe133ff0726af00d435fab2509f1e5.tar.gz
Improve model validation
Diffstat (limited to 'app/models/prometheus_metric.rb')
-rw-r--r--app/models/prometheus_metric.rb13
1 files changed, 2 insertions, 11 deletions
diff --git a/app/models/prometheus_metric.rb b/app/models/prometheus_metric.rb
index 9527c596088..dbb0fd19b74 100644
--- a/app/models/prometheus_metric.rb
+++ b/app/models/prometheus_metric.rb
@@ -23,7 +23,8 @@ class PrometheusMetric < ActiveRecord::Base
validates :y_label, presence: true
validates :unit, presence: true
- validate :require_project
+ validates :project, presence: true, unless: :common?
+ validates :project, absence: true, if: :common?
scope :common, -> { where(common: true) }
@@ -85,14 +86,4 @@ class PrometheusMetric < ActiveRecord::Base
}
end
end
-
- private
-
- def require_project
- if project
- errors.add(:project, "cannot be set if this is common metric") if common?
- else
- errors.add(:project, "has to be set when this is project-specific metric") unless common?
- end
- end
end