Skip to content

Commit

Permalink
Clear out all votes when reloading a division
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
henare committed Nov 23, 2015
1 parent cd9079a commit 047a641
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/data_loader/ukraine/vote_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ 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) ||
Member.find_by!(person_id: v["voter_id"], party: party_name) # Fallback when current_on isn't quite right

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

Expand Down

0 comments on commit 047a641

Please sign in to comment.