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..95b1660aa 100644
--- a/app/views/polls/_poll_group.html.erb
+++ b/app/views/polls/_poll_group.html.erb
@@ -29,30 +29,13 @@
- <% 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 %>
-
- <%= 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 %>
-
+ <% if poll.questions.one? %>
+
<%= link_to_poll poll.questions.first.title, poll %>
<%= poll_dates(poll) %>
+ <% else %>
+
<%= link_to_poll poll.name, poll %>
+ <%= poll_dates(poll) %>
+
<% poll.questions.each do |question| %>
- <%= question.title %>
diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb
index f9c420076..8470cd100 100644
--- a/spec/features/polls/polls_spec.rb
+++ b/spec/features/polls/polls_spec.rb
@@ -114,7 +114,7 @@ feature "Polls" do
visit polls_path
- expect(page).to have_link("Poll with stats", href: stats_poll_path(poll))
+ expect(page).to have_link("Poll with stats", href: stats_poll_path(poll.slug))
end
scenario "Poll title link to results if enabled" do
@@ -122,7 +122,7 @@ feature "Polls" do
visit polls_path
- expect(page).to have_link("Poll with results", href: results_poll_path(poll))
+ expect(page).to have_link("Poll with results", href: results_poll_path(poll.slug))
end
end