From 858ec0f5480ca583b470b6dab1e86e417c748fc7 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Tue, 11 Oct 2016 03:51:19 +0300 Subject: [PATCH] Handle the edge case of having no votes cast yet --- app/models/conference.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index 4abed90..f327e52 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -41,7 +41,7 @@ class Conference < ActiveRecord::Base end def has_vote_results? - vote_data_updated_at.present? + vote_data_updated_at.present? and number_of_ballots_cast > 0 end def has_voting_endpoint? @@ -77,7 +77,7 @@ class Conference < ActiveRecord::Base def save conference.transaction do - conference.update number_of_ballots_cast: number_of_ballots + conference.number_of_ballots_cast = number_of_ballots ranking.all?(&:save) or raise ActiveRecord::Rollback conference.touch :vote_data_updated_at conference.save or raise ActiveRecord::Rollback