Files
nairobi/app/helpers/votes_helper.rb
Javi Martín 86ad2df46d Unify code in debates/legislation vote links
We were using the same code to render links to agree and disagree, so we
can extract a new component for this code.

We're also adding component tests to make it easier to test whether
we're breaking anything while refactoring, although the code is probably
already covered by system tests.

Since the votes mixin was only used in one place, we're removing it and
moving most of its code to a new CSS file for the shared component.
2022-02-21 18:47:13 +01:00

16 lines
366 B
Ruby

module VotesHelper
def debate_percentage_of_likes(debate)
debate.likes.percent_of(debate.total_votes)
end
def votes_percentage(vote, debate)
return "0%" if debate.total_votes == 0
if vote == "likes"
"#{debate_percentage_of_likes(debate)}%"
elsif vote == "dislikes"
"#{100 - debate_percentage_of_likes(debate)}%"
end
end
end