shows "0%" when there's zero votes

Closes #97
This commit is contained in:
Juanjo Bazán
2015-08-05 17:56:14 +02:00
parent d23ce151a6
commit 64f5c4e7f1
2 changed files with 15 additions and 1 deletions

View File

@@ -5,7 +5,7 @@ module ApplicationHelper
end
def percentage(vote, debate)
return if debate.total_votes == 0
return "0%" if debate.total_votes == 0
debate.send(vote).percent_of(debate.total_votes).to_s + "%"
end

View File

@@ -13,6 +13,20 @@ feature 'Votes' do
visit debate_path(@debate)
end
scenario 'Show no votes' do
visit debate_path(@debate)
expect(page).to have_content "0 votes"
within('#in_favor') do
expect(page).to have_content "0%"
end
within('#against') do
expect(page).to have_content "0%"
end
end
scenario 'Show' do
vote = create(:vote, voter: @manuela, votable: @debate, vote_flag: true)
vote = create(:vote, voter: @pablo, votable: @debate, vote_flag: false)