Refactor Budget's on hold phases to constant, plus alignments

This commit is contained in:
Bertocq
2018-01-10 01:09:13 +01:00
parent cb1151f1d6
commit d8ceff1a53

View File

@@ -5,6 +5,8 @@ class Budget < ActiveRecord::Base
PHASES = %w(drafting accepting reviewing selecting valuating balloting
reviewing_ballots finished).freeze
ON_HOLD_PHASES = %w(reviewing valuating reviewing_ballots).freeze
CURRENCY_SYMBOLS = %w(€ $ £ ¥).freeze
validates :name, presence: true, uniqueness: true
@@ -19,17 +21,17 @@ class Budget < ActiveRecord::Base
before_validation :sanitize_descriptions
scope :on_hold, -> { where(phase: %w(reviewing valuating reviewing_ballots")) }
scope :drafting, -> { where(phase: "drafting") }
scope :on_hold, -> { where(phase: ON_HOLD_PHASES) }
scope :drafting, -> { where(phase: "drafting") }
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 :finished, -> { where(phase: "finished") }
scope :current, -> { where.not(phase: "finished") }
scope :current, -> { where.not(phase: "finished") }
def description
send("description_#{phase}").try(:html_safe)
@@ -84,7 +86,7 @@ class Budget < ActiveRecord::Base
end
def on_hold?
reviewing? || valuating? || reviewing_ballots?
ON_HOLD_PHASES.include?(phase)
end
def current?