adds helper to show the right progress bar

This commit is contained in:
Juanjo Bazán
2015-09-13 19:00:11 +02:00
parent 2eefdb2499
commit 9dee1bc8b2
3 changed files with 35 additions and 1 deletions

View File

@@ -0,0 +1,11 @@
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
else 100
end
end
end

View File

@@ -2,7 +2,7 @@
<div class="supports">
<div class="progress small-12 radius">
<span class="meter" style="width: 10%;"></span>
<span class="meter" style="width: <%= progress_bar_percentage(proposal) %>%;"></span>
</div>
<span class="total-supports">

View File

@@ -0,0 +1,23 @@
require 'rails_helper'
describe ProposalsHelper do
describe "#progress_bar_percentage" do
it "should be 0 if no votes" do
proposal = create(:proposal)
expect(progress_bar_percentage(proposal)).to eq 0
end
it "should be a between 1 and 100 if there are votes but less than needed" do
proposal = create(:proposal, cached_votes_up: Proposal.votes_needed_for_success/2)
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
end
end
end