This way we can make the view code a bit easier to read. We're also changing the order of the conditions a little bit so we only check for the presence of a current user once. To make sure we aren't breaking anything with these changes, we're adding some tests. We're also replacing one system test checking content with a component test, since component tests are much faster.
23 lines
465 B
Ruby
23 lines
465 B
Ruby
class Debates::VotesComponent < ApplicationComponent
|
|
attr_reader :debate
|
|
delegate :css_classes_for_vote, :current_user, :link_to_verify_account, :votes_percentage, to: :helpers
|
|
|
|
def initialize(debate)
|
|
@debate = debate
|
|
end
|
|
|
|
private
|
|
|
|
def voted_classes
|
|
@voted_classes ||= css_classes_for_vote(debate)
|
|
end
|
|
|
|
def can_vote?
|
|
debate.votable_by?(current_user)
|
|
end
|
|
|
|
def organization?
|
|
current_user&.organization?
|
|
end
|
|
end
|