Add next/prev enabled phase helper functions to Budget::Phase with model specs

This commit is contained in:
Bertocq
2018-01-15 20:35:52 +01:00
parent 59fb0b562c
commit 21b62106e5
2 changed files with 51 additions and 7 deletions

View File

@@ -25,6 +25,14 @@ class Budget
scope :reviewing_ballots, -> { find_by_kind('reviewing_ballots')}
scope :finished, -> { find_by_kind('finished')}
def next_enabled_phase
next_phase&.enabled? ? next_phase : next_phase&.next_enabled_phase
end
def prev_enabled_phase
prev_phase&.enabled? ? prev_phase : prev_phase&.prev_enabled_phase
end
def dates_range_valid?
if starts_at.present? && ends_at.present? && starts_at >= ends_at
errors.add(:starts_at, I18n.t('budgets.phases.errors.dates_range_invalid'))