From 5ca528d2ce30a1488ca8c7d3790b3bd6b480ead1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 23 Apr 2019 14:05:37 +0200 Subject: [PATCH] Extract method to link to a poll --- app/helpers/polls_helper.rb | 10 ++++++++++ app/views/polls/_poll_group.html.erb | 20 ++------------------ spec/features/polls/polls_spec.rb | 4 ++-- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 06d2f78f7..2faf9b3f8 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -49,6 +49,16 @@ module PollsHelper question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at > vote.updated_at } end + def link_to_poll(text, poll) + if poll.results_enabled? + link_to text, results_poll_path(id: poll.slug || poll.id) + elsif poll.stats_enabled? + link_to text, stats_poll_path(id: poll.slug || poll.id) + else + link_to text, poll_path(id: poll.slug || poll.id) + end + end + def show_stats_or_results? @poll.expired? && (@poll.results_enabled? || @poll.stats_enabled?) end diff --git a/app/views/polls/_poll_group.html.erb b/app/views/polls/_poll_group.html.erb index 8bd388b10..1de745cdf 100644 --- a/app/views/polls/_poll_group.html.erb +++ b/app/views/polls/_poll_group.html.erb @@ -31,27 +31,11 @@
<% if poll.questions.count == 1 %> <% poll.questions.each do |question| %> -

- <% if poll.results_enabled? %> - <%= link_to question.title, results_poll_path(poll) %> - <% elsif poll.stats_enabled? %> - <%= link_to question.title, stats_poll_path(poll) %> - <% else %> - <%= link_to question.title, poll %> - <% end %> -

+

<%= link_to_poll question.title, poll %>

<%= poll_dates(poll) %> <% end %> <% else %> -

- <% if poll.results_enabled? %> - <%= link_to poll.name, results_poll_path(poll) %> - <% elsif poll.stats_enabled? %> - <%= link_to poll.name, stats_poll_path(poll) %> - <% else %> - <%= link_to poll.name, poll_path(id: poll.slug || poll.id) %> - <% end %> -

+

<%= link_to_poll poll.name, poll %>

<%= poll_dates(poll) %>