Adds simple Budget specs

This commit is contained in:
kikito
2016-05-20 17:56:05 +02:00
parent cf0b7a53b0
commit fdc8636e12
3 changed files with 29 additions and 1 deletions

View File

@@ -1,5 +1,12 @@
class Budget < ActiveRecord::Base class Budget < ActiveRecord::Base
VALID_PHASES = %W{on_hold accepting selecting balloting finished}
validates :phase, inclusion: { in: VALID_PHASES }
has_many :investments
has_many :ballots
def on_hold? def on_hold?
phase == "on_hold" phase == "on_hold"
end end
@@ -20,4 +27,5 @@ class Budget < ActiveRecord::Base
phase == "finished" phase == "finished"
end end
end end

View File

@@ -358,4 +358,9 @@ FactoryGirl.define do
sequence(:name) { |n| "District #{n}" } sequence(:name) { |n| "District #{n}" }
census_code { '01' } census_code { '01' }
end end
factory :budget do
sequence(:name) {|n| "Budget #{n}" }
phase "on_hold"
end
end end

View File

@@ -0,0 +1,15 @@
require 'rails_helper'
describe Budget do
it "validates the phase" do
budget = create(:budget)
Budget::VALID_PHASES.each do |phase|
budget.phase = phase
expect(budget).to be_valid
end
budget.phase = 'inexisting'
expect(budget).to_not be_valid
end
end