From 63854bee6c387fc82b41f1a8eea968790541cf29 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 10 Feb 2022 14:26:54 +0100 Subject: Fix poll votes not being properly reset on poll change (#17498) * Fix poll votes not being properly reset on poll change * Fix and add tests * Fix poll update handling when the number of options changes --- app/models/poll.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/models/poll.rb') diff --git a/app/models/poll.rb b/app/models/poll.rb index 71b5e191f..ba08309a1 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -83,6 +83,12 @@ class Poll < ApplicationRecord end end + def reset_votes! + self.cached_tallies = options.map { 0 } + self.votes_count = 0 + votes.delete_all unless new_record? + end + private def prepare_cached_tallies -- cgit