Exclude nil balloters from vote phase participants

The `user_id` can be `nil` for ballots.
This commit is contained in:
Javi Martín
2019-03-26 20:34:03 +01:00
parent 0a578f2775
commit cf32cc940b
2 changed files with 9 additions and 1 deletions

View File

@@ -65,7 +65,7 @@ class Budget::Stats
end end
def balloters def balloters
budget.ballots.where("ballot_lines_count > ?", 0).pluck(:user_id) budget.ballots.where("ballot_lines_count > ?", 0).pluck(:user_id).compact
end end
def poll_ballot_voters def poll_ballot_voters

View File

@@ -69,6 +69,14 @@ describe Budget::Stats do
expect(stats.generate[:total_participants_vote_phase]).to be 1 expect(stats.generate[:total_participants_vote_phase]).to be 1
end end
it "doesn't count nil user ids" do
create(:budget_ballot_line, investment: investment,
ballot: create(:budget_ballot, budget: budget, user: nil, physical: true)
)
expect(stats.generate[:total_participants_vote_phase]).to be 0
end
end end
describe "#total_participants_web" do describe "#total_participants_web" do