app/models/effective/cpd_cycle.rb in effective_cpd-0.0.1 vs app/models/effective/cpd_cycle.rb in effective_cpd-0.1
- old
+ new
@@ -47,12 +47,19 @@
build_from_cycle(cycle: cycle) if cycle
end
validates :title, presence: true
validates :start_at, presence: true
+ validates :required_score, numericality: { greater_than: 0, allow_nil: true }
validate(if: -> { start_at.present? && end_at.present? }) do
self.errors.add(:end_at, 'must be after the start date') unless end_at > start_at
+ end
+
+ before_destroy do
+ if (count = cpd_statements.length) > 0
+ raise("#{count} statement belong to this cycle")
+ end
end
def self.latest_cycle
order(id: :desc).first
end