Extract method to link to a poll
This commit is contained in:
@@ -49,6 +49,16 @@ module PollsHelper
|
|||||||
question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at > vote.updated_at }
|
question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at > vote.updated_at }
|
||||||
end
|
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?
|
def show_stats_or_results?
|
||||||
@poll.expired? && (@poll.results_enabled? || @poll.stats_enabled?)
|
@poll.expired? && (@poll.results_enabled? || @poll.stats_enabled?)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,27 +31,11 @@
|
|||||||
<div class="dates"></div>
|
<div class="dates"></div>
|
||||||
<% if poll.questions.count == 1 %>
|
<% if poll.questions.count == 1 %>
|
||||||
<% poll.questions.each do |question| %>
|
<% poll.questions.each do |question| %>
|
||||||
<h4>
|
<h4><%= link_to_poll question.title, poll %></h4>
|
||||||
<% 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 %>
|
|
||||||
</h4>
|
|
||||||
<%= poll_dates(poll) %>
|
<%= poll_dates(poll) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<h4>
|
<h4><%= link_to_poll poll.name, poll %></h4>
|
||||||
<% 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 %>
|
|
||||||
</h4>
|
|
||||||
<%= poll_dates(poll) %>
|
<%= poll_dates(poll) %>
|
||||||
<ul class="margin-top">
|
<ul class="margin-top">
|
||||||
<% poll.questions.each do |question| %>
|
<% poll.questions.each do |question| %>
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ feature "Polls" do
|
|||||||
|
|
||||||
visit polls_path
|
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
|
end
|
||||||
|
|
||||||
scenario "Poll title link to results if enabled" do
|
scenario "Poll title link to results if enabled" do
|
||||||
@@ -122,7 +122,7 @@ feature "Polls" do
|
|||||||
|
|
||||||
visit polls_path
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user