Add a test for an edge case calculating winners
We weren't testing what happens if the next investment exceeds the budget, but the following one doesn't.
This commit is contained in:
@@ -18,6 +18,16 @@ describe Budget::Result do
|
|||||||
expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 600])
|
expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 600])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "selects cheaper investments when running out of budget" do
|
||||||
|
create(:budget_investment, :selected, heading: heading, price: 800, ballot_lines_count: 900)
|
||||||
|
create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800)
|
||||||
|
create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 600)
|
||||||
|
|
||||||
|
Budget::Result.new(budget, heading).calculate_winners
|
||||||
|
|
||||||
|
expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 600])
|
||||||
|
end
|
||||||
|
|
||||||
it "excludes incompatible investments" do
|
it "excludes incompatible investments" do
|
||||||
investment1 = create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900, winner: false)
|
investment1 = create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900, winner: false)
|
||||||
investment2 = create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800, winner: false)
|
investment2 = create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800, winner: false)
|
||||||
|
|||||||
Reference in New Issue
Block a user