Disable calculating winners during balloting

Calculating winners before the balloting is over is useless (results
aren't published at that point) and can lead to the wrong results since
users are still voting and results might change.

And we were showing the button to calculate winners even when a budget
had finished. However, in this case the action to calculate winners did
nothing, which resulted in administrators seeing nothing happened after
pressing the button.
This commit is contained in:
Javi Martín
2021-08-30 15:11:02 +02:00
parent 2b709f1a36
commit 0a14337580
11 changed files with 81 additions and 36 deletions

View File

@@ -0,0 +1,65 @@
require "rails_helper"
describe Admin::Budgets::CalculateWinnersButtonComponent, controller: Admin::BaseController do
let(:budget) { create(:budget) }
let(:component) { Admin::Budgets::CalculateWinnersButtonComponent.new(budget) }
before { sign_in(create(:administrator).user) }
it "renders when reviewing ballots" do
budget.update!(phase: "reviewing_ballots")
render_inline component
expect(page).to have_button "Calculate Winner Investments"
expect(page).not_to have_button "Recalculate Winner Investments"
end
it "does not render before balloting has finished" do
budget.update!(phase: "balloting")
render_inline component
expect(page).not_to have_button "Calculate Winner Investments"
expect(page).not_to have_button "Recalculate Winner Investments"
end
it "does not render after the budget process has finished" do
budget.update!(phase: "finished")
render_inline component
expect(page).not_to have_button "Calculate Winner Investments"
expect(page).not_to have_button "Recalculate Winner Investments"
end
context "budget with winners" do
before { create(:budget_investment, :winner, budget: budget) }
it "renders when reviewing ballots" do
budget.update!(phase: "reviewing_ballots")
render_inline component
expect(page).to have_button "Recalculate Winner Investments"
expect(page).not_to have_button "Calculate Winner Investments"
end
it "does not render before balloting has finished" do
budget.update!(phase: "balloting")
render_inline component
expect(page).not_to have_button "Calculate Winner Investments"
expect(page).not_to have_button "Recalculate Winner Investments"
end
it "does not render after the budget process has finished" do
budget.update!(phase: "finished")
render_inline component
expect(page).not_to have_button "Calculate Winner Investments"
expect(page).not_to have_button "Recalculate Winner Investments"
end
end
end