From cf271fe33aa9f70308796ec55ecbcaa2a8c8e253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 18 Dec 2015 13:15:00 +0100 Subject: [PATCH] uses proposal total_votes for % helper methods --- app/helpers/proposals_helper.rb | 4 ++-- spec/helpers/proposals_helper_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index d4d7bca64..f01abc053 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -3,13 +3,13 @@ module ProposalsHelper def progress_bar_percentage(proposal) case proposal.cached_votes_up when 0 then 0 - when 1..Proposal.votes_needed_for_success then (proposal.cached_votes_up.to_f * 100 / Proposal.votes_needed_for_success).floor + when 1..Proposal.votes_needed_for_success then (proposal.total_votes.to_f * 100 / Proposal.votes_needed_for_success).floor else 100 end end def supports_percentage(proposal) - percentage = (proposal.cached_votes_up.to_f * 100 / Proposal.votes_needed_for_success) + percentage = (proposal.total_votes.to_f * 100 / Proposal.votes_needed_for_success) case percentage when 0 then "0%" when 0..(0.1) then "0.1%" diff --git a/spec/helpers/proposals_helper_spec.rb b/spec/helpers/proposals_helper_spec.rb index 983f43572..82206afb5 100644 --- a/spec/helpers/proposals_helper_spec.rb +++ b/spec/helpers/proposals_helper_spec.rb @@ -13,6 +13,11 @@ describe ProposalsHelper do expect(progress_bar_percentage(proposal)).to eq 50 end + it "should take into account the physical votes" do + proposal = create(:proposal, cached_votes_up: ((Proposal.votes_needed_for_success/2)-100), physical_votes: 100) + expect(progress_bar_percentage(proposal)).to eq 50 + end + it "should be 100 if there are more votes than needed" do proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success*2) expect(progress_bar_percentage(proposal)).to eq 100 @@ -39,6 +44,11 @@ describe ProposalsHelper do proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success*2) expect(supports_percentage(proposal)).to eq "100%" end + + it "should take into account the physical votes" do + proposal = create(:proposal, physical_votes: Proposal.votes_needed_for_success/2) + expect(supports_percentage(proposal)).to eq "50%" + end end end \ No newline at end of file