uses proposal total_votes for % helper methods
This commit is contained in:
@@ -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%"
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user