Skip to content

Commit

Permalink
Merge pull request #3519 from consul/backport-remove_custom_poll_grou…
Browse files Browse the repository at this point in the history
…p_file

Simplify link to poll
  • Loading branch information
javierm authored May 23, 2019
2 parents 7abeb59 + 2d29243 commit afdc708
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
10 changes: 10 additions & 0 deletions app/helpers/polls_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ def voted_before_sign_in(question)
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
Expand Down
27 changes: 5 additions & 22 deletions app/views/polls/_poll_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,13 @@
</div>
<div class="small-12 medium-6 column" data-equalizer-watch>
<div class="dates"></div>
<% if poll.questions.count == 1 %>
<% poll.questions.each do |question| %>
<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) %>
<% end %>
<% if poll.questions.one? %>
<h4><%= link_to_poll poll.questions.first.title, poll %></h4>
<%= poll_dates(poll) %>
<% else %>
<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>
<h4><%= link_to_poll poll.name, poll %></h4>
<%= poll_dates(poll) %>

<ul class="margin-top">
<% poll.questions.each do |question| %>
<li><%= question.title %></li>
Expand Down
4 changes: 2 additions & 2 deletions spec/features/polls/polls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@

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
poll = create(:poll, name: "Poll with results", stats_enabled: true, results_enabled: true)

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

Expand Down

0 comments on commit afdc708

Please sign in to comment.