From cf32cc940b16a937af4b8cf67071ab1c1007d06b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 26 Mar 2019 20:34:03 +0100 Subject: [PATCH] Exclude nil balloters from vote phase participants The `user_id` can be `nil` for ballots. --- app/models/budget/stats.rb | 2 +- spec/models/budget/stats_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index 541c56c3b..7b2e91e74 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -65,7 +65,7 @@ class Budget::Stats end def balloters - budget.ballots.where("ballot_lines_count > ?", 0).pluck(:user_id) + budget.ballots.where("ballot_lines_count > ?", 0).pluck(:user_id).compact end def poll_ballot_voters diff --git a/spec/models/budget/stats_spec.rb b/spec/models/budget/stats_spec.rb index 99044648c..8eb18ae14 100644 --- a/spec/models/budget/stats_spec.rb +++ b/spec/models/budget/stats_spec.rb @@ -69,6 +69,14 @@ describe Budget::Stats do expect(stats.generate[:total_participants_vote_phase]).to be 1 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 describe "#total_participants_web" do