Adds simple Budget specs
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
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?
|
||||
phase == "on_hold"
|
||||
end
|
||||
@@ -20,4 +27,5 @@ class Budget < ActiveRecord::Base
|
||||
phase == "finished"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -358,4 +358,9 @@ FactoryGirl.define do
|
||||
sequence(:name) { |n| "District #{n}" }
|
||||
census_code { '01' }
|
||||
end
|
||||
|
||||
factory :budget do
|
||||
sequence(:name) {|n| "Budget #{n}" }
|
||||
phase "on_hold"
|
||||
end
|
||||
end
|
||||
|
||||
15
spec/models/budget_spec.rb
Normal file
15
spec/models/budget_spec.rb
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user