From 047a641a2bbbb6fa9f0e1cae90e92a7dfbc29e7b Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 23 Nov 2015 13:34:39 +1100 Subject: [PATCH] Clear out all votes when reloading a division Previously if the member was incorrect in the original load it could result in orphan votes being left in. It's safer for us to reload all the votes completely. --- lib/data_loader/ukraine/vote_events.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/data_loader/ukraine/vote_events.rb b/lib/data_loader/ukraine/vote_events.rb index 24ce9e117..acc136dd1 100644 --- a/lib/data_loader/ukraine/vote_events.rb +++ b/lib/data_loader/ukraine/vote_events.rb @@ -33,6 +33,7 @@ def load! votes = v_e["votes"] Rails.logger.info "Loading #{votes.count} votes..." + division.votes.destroy_all votes.each do |v| party_name = people.party_name_from_id(v["group_id"]) member = Member.current_on(division.date).find_by(person_id: v["voter_id"], party: party_name) || @@ -40,10 +41,7 @@ def load! vote = division.votes.find_or_initialize_by(member: member) if option = popolo_to_publicwhip_vote(v["option"]) - vote.vote = option - vote.save! - else - vote.destroy + division.votes.create!(member: member, vote: option) end end