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

View File

@@ -195,20 +195,32 @@ FactoryGirl.define do
factory :budget do
sequence(:name) { |n| "Budget #{n}" }
currency_symbol ""
phase 'on_hold'
phase 'accepting'
trait :accepting do
phase 'accepting'
end
trait :reviewing do
phase 'reviewing'
end
trait :selecting do
phase 'selecting'
end
trait :valuating do
phase 'valuating'
end
trait :balloting do
phase 'balloting'
end
trait :reviewing_ballots do
phase 'reviewing_ballots'
end
trait :finished do
phase 'finished'
end

View File

@@ -582,7 +582,7 @@ feature 'Ballots' do
end
scenario "Balloting is disabled when budget isn't in the balotting phase", :js do
budget.update(phase: 'on_hold')
budget.update(phase: 'accepting')
bi1 = create(:budget_investment, :selected, heading: california, price: 600)

View File

@@ -88,7 +88,7 @@ feature 'Votes' do
scenario 'Disable voting on spending proposals', :js do
login_as(@manuela)
budget.update(phase: "on_hold")
budget.update(phase: "reviewing")
investment = create(:budget_investment, budget: budget, heading: heading)
visit budget_investments_path(budget, heading_id: heading.id)

View File

@@ -318,8 +318,8 @@ describe Budget::Investment do
expect(investment.reason_for_not_being_ballotable_by(user, ballot)).to eq(:organization)
end
it "rejects votes when voting is not allowed (via admin setting)" do
budget.phase = "on_hold"
it "rejects votes when voting is not allowed (wrong phase)" do
budget.phase = "reviewing"
expect(investment.reason_for_not_being_ballotable_by(user, ballot)).to eq(:no_ballots_allowed)
end

View File

@@ -15,18 +15,24 @@ describe Budget do
end
it "produces auxiliary methods" do
budget.phase = "on_hold"
expect(budget).to be_on_hold
budget.phase = "accepting"
expect(budget).to be_accepting
budget.phase = "reviewing"
expect(budget).to be_reviewing
budget.phase = "selecting"
expect(budget).to be_selecting
budget.phase = "valuating"
expect(budget).to be_valuating
budget.phase = "balloting"
expect(budget).to be_balloting
budget.phase = "reviewing_ballots"
expect(budget).to be_reviewing_ballots
budget.phase = "finished"
expect(budget).to be_finished
end