Skip to content

Commit

Permalink
Refactor Budget's on hold phases to constant, plus alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
bertocq committed Jan 10, 2018
1 parent cb1151f commit d8ceff1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/models/budget.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -84,7 +86,7 @@ def balloting_or_later?
end

def on_hold?
reviewing? || valuating? || reviewing_ballots?
ON_HOLD_PHASES.include?(phase)
end

def current?
Expand Down

0 comments on commit d8ceff1

Please sign in to comment.