Adds new phases to budget and fixes specs

This commit is contained in:
kikito
2016-12-30 18:43:15 +01:00
parent 181749b4f6
commit fa50e3f215
6 changed files with 47 additions and 15 deletions

View File

@@ -3,7 +3,7 @@ class Budget < ActiveRecord::Base
include Sanitizable
include Measurable
VALID_PHASES = %W{on_hold accepting selecting balloting finished}.freeze
VALID_PHASES = %W{accepting reviewing selecting valuating balloting reviewing_ballots finished}.freeze
CURRENCY_SYMBOLS = %W{€ $ £ ¥}.freeze
validates :name, presence: true
@@ -15,35 +15,49 @@ class Budget < ActiveRecord::Base
has_many :groups, dependent: :destroy
has_many :headings, through: :groups
scope :on_hold, -> { where(phase: "on_hold") }
scope :on_hold, -> { where(phase: ["reviewing", "valuating", "reviewing_ballots"]) }
scope :accepting, -> { where(phase: "accepting") }
scope :reviewing, -> { where(phase: "reviewing") }
scope :selecting, -> { where(phase: "selecting") }
scope :valuating, -> { where(phase: "valuating") }
scope :balloting, -> { where(phase: "balloting") }
scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") }
scope :finished, -> { where(phase: "finished") }
scope :current, -> { where.not(phase: "finished") }
scope :valuating, -> { where(valuating: true) }
def on_hold?
phase == "on_hold"
end
def accepting?
phase == "accepting"
end
def reviewing?
phase == "reviewing"
end
def selecting?
phase == "selecting"
end
def valuating?
phase == "valuating"
end
def balloting?
phase == "balloting"
end
def reviewing_ballots?
phase == "reviewing_ballots"
end
def finished?
phase == "finished"
end
def on_hold?
reviewing? || valuating? || reviewing_ballots?
end
def current?
!finished?
end