From 4cccb936779f57fbcc36ecc78dc796bd2495c539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Sun, 11 Nov 2018 14:54:35 +0100 Subject: [PATCH 1/2] fix poll accuracy results using floats --- app/models/poll/question/answer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index f3bd4297f..db218a7de 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -46,7 +46,7 @@ class Poll::Question::Answer < ActiveRecord::Base end def total_votes_percentage - question.answers_total_votes.zero? ? 0 : (total_votes * 100) / question.answers_total_votes + question.answers_total_votes.zero? ? 0 : (total_votes * 100.0) / question.answers_total_votes end def set_most_voted From d8df2c1fa8150f2d96c572f957d2b694dd6e3482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Sun, 11 Nov 2018 14:54:58 +0100 Subject: [PATCH 2/2] adds proper accuracy to spec --- spec/features/polls/results_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/features/polls/results_spec.rb b/spec/features/polls/results_spec.rb index 326344dd9..0dfb93f1a 100644 --- a/spec/features/polls/results_spec.rb +++ b/spec/features/polls/results_spec.rb @@ -42,14 +42,14 @@ feature 'Poll Results' do expect(page).to have_content(question2.title) within("#question_#{question1.id}_results_table") do - expect(find("#answer_#{answer1.id}_result")).to have_content("2 (66.0%)") - expect(find("#answer_#{answer2.id}_result")).to have_content("1 (33.0%)") + expect(find("#answer_#{answer1.id}_result")).to have_content("2 (66.67%)") + expect(find("#answer_#{answer2.id}_result")).to have_content("1 (33.33%)") end within("#question_#{question2.id}_results_table") do - expect(find("#answer_#{answer3.id}_result")).to have_content("1 (33.0%)") - expect(find("#answer_#{answer4.id}_result")).to have_content("1 (33.0%)") - expect(find("#answer_#{answer5.id}_result")).to have_content("1 (33.0%)") + expect(find("#answer_#{answer3.id}_result")).to have_content("1 (33.33%)") + expect(find("#answer_#{answer4.id}_result")).to have_content("1 (33.33%)") + expect(find("#answer_#{answer5.id}_result")).to have_content("1 (33.33%)") end end end