Activates and refactors budget/ballot/line_spec
This commit is contained in:
@@ -1,104 +1,50 @@
|
||||
require 'rails_helper'
|
||||
|
||||
xdescribe "Budget::Ballot::Line" do
|
||||
|
||||
let(:ballot_line) { build(:budget_ballot_line) }
|
||||
describe "Budget::Ballot::Line" do
|
||||
|
||||
describe 'Validations' do
|
||||
let(:budget){ create(:budget) }
|
||||
let(:group){ create(:budget_group, budget: budget) }
|
||||
let(:heading){ create(:budget_heading, group: group, price: 10000000) }
|
||||
let(:investment){ create(:budget_investment, :feasible, price: 5000000, heading: heading) }
|
||||
let(:ballot) { create(:budget_ballot, budget: budget) }
|
||||
let(:ballot_line) { build(:budget_ballot_line, ballot: ballot, investment: investment) }
|
||||
|
||||
it "should be valid" do
|
||||
it "should be valid and automatically denormallyze budget, group and heading when validated" do
|
||||
expect(ballot_line).to be_valid
|
||||
end
|
||||
|
||||
it "should be invalid if missing id from ballot|budget|group|heading|investment" do
|
||||
budget = create(:budget)
|
||||
group = create(:budget_group, budget: budget)
|
||||
heading = create(:budget_heading, group: group, price: 10000000)
|
||||
investment = create(:budget_investment, :feasible, price: 5000000, heading: heading)
|
||||
ballot = create(:budget_ballot, budget: budget)
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: heading, investment: investment)
|
||||
expect(ballot_line).to be_valid
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: nil, budget: budget, group: group, heading: heading, investment: investment)
|
||||
expect(ballot_line).to_not be_valid
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: nil, group: group, heading: heading, investment: investment)
|
||||
expect(ballot_line).to_not be_valid
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: nil, heading: heading, investment: investment)
|
||||
expect(ballot_line).to_not be_valid
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: nil, investment: investment)
|
||||
expect(ballot_line).to_not be_valid
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: heading, investment: nil)
|
||||
expect(ballot_line).to_not be_valid
|
||||
expect(ballot_line.budget).to eq(budget)
|
||||
expect(ballot_line.group).to eq(group)
|
||||
expect(ballot_line.heading).to eq(heading)
|
||||
end
|
||||
|
||||
describe 'Money' do
|
||||
it "should not be valid if insufficient funds" do
|
||||
budget = create(:budget)
|
||||
group = create(:budget_group, budget: budget)
|
||||
heading = create(:budget_heading, group: group, price: 10000000)
|
||||
investment = create(:budget_investment, :feasible, price: heading.price + 1, heading: heading)
|
||||
ballot = create(:budget_ballot, budget: budget)
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: heading, investment: investment)
|
||||
|
||||
investment.update(price: heading.price + 1)
|
||||
expect(ballot_line).to_not be_valid
|
||||
end
|
||||
|
||||
it "should be valid if sufficient funds" do
|
||||
budget = create(:budget)
|
||||
group = create(:budget_group, budget: budget)
|
||||
heading = create(:budget_heading, group: group, price: 10000000)
|
||||
investment = create(:budget_investment, :feasible, price: heading.price - 1, heading: heading, )
|
||||
ballot = create(:budget_ballot, budget: budget)
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: heading, investment: investment)
|
||||
|
||||
investment.update(price: heading.price - 1)
|
||||
expect(ballot_line).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Feasibility' do
|
||||
it "should not be valid if investment is unfeasible" do
|
||||
budget = create(:budget)
|
||||
group = create(:budget_group, budget: budget)
|
||||
heading = create(:budget_heading, group: group, price: 10000000)
|
||||
investment = create(:budget_investment, :feasible, price: 20000, feasibility: "unfeasible")
|
||||
ballot = create(:budget_ballot, budget: budget)
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: heading, investment: investment)
|
||||
|
||||
investment.update(feasibility: "unfeasible")
|
||||
expect(ballot_line).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid if investment feasibility is undecided" do
|
||||
budget = create(:budget)
|
||||
group = create(:budget_group, budget: budget)
|
||||
heading = create(:budget_heading, group: group, price: 10000000)
|
||||
investment = create(:budget_investment, price: 20000, feasibility: "undecided")
|
||||
ballot = create(:budget_ballot, budget: budget)
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: heading, investment: investment)
|
||||
|
||||
investment.update(feasibility: "undecided", price: 20000)
|
||||
expect(ballot_line).to_not be_valid
|
||||
end
|
||||
|
||||
xit "should be valid if investment is feasible" do
|
||||
budget = create(:budget)
|
||||
group = create(:budget_group, budget: budget)
|
||||
heading = create(:budget_heading, group: group, price: 10000000)
|
||||
investment = create(:budget_investment, price: 20000, feasibility: "feasible")
|
||||
ballot = create(:budget_ballot, budget: budget)
|
||||
|
||||
ballot_line = build(:budget_ballot_line, ballot: ballot, budget: budget, group: group, heading: heading, investment: investment)
|
||||
|
||||
it "should be valid if investment is feasible" do
|
||||
investment.update(feasibility: "feasible", price: 20000)
|
||||
expect(ballot_line).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user