Validate date ranges for legislation process
Only validates start and end dates for the whole process or a phase, not overlap between phases, as they are permitted, at least for now.
This commit is contained in:
@@ -18,6 +18,7 @@ class Legislation::Process < ActiveRecord::Base
|
||||
validates :allegations_start_date, presence: true
|
||||
validates :allegations_end_date, presence: true
|
||||
validates :final_publication_date, presence: true
|
||||
validate :valid_date_ranges
|
||||
|
||||
scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current).order('id DESC') }
|
||||
scope :next, -> { where("start_date > ?", Date.current).order('id DESC') }
|
||||
@@ -57,4 +58,13 @@ class Legislation::Process < ActiveRecord::Base
|
||||
def total_comments
|
||||
questions.map(&:comments_count).sum
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_date_ranges
|
||||
errors.add(:end_date, :invalid_date_range) if end_date < start_date
|
||||
errors.add(:debate_end_date, :invalid_date_range) if debate_end_date < debate_start_date
|
||||
errors.add(:allegations_end_date, :invalid_date_range) if allegations_end_date < allegations_start_date
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user