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:
Javi Martín
2019-09-21 12:21:48 +02:00
parent 5a934de5a6
commit 1bb53b11fb

View File

@@ -18,6 +18,16 @@ describe Budget::Result do
expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 600])
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
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)