Skip to content

Commit

Permalink
Merge pull request consuldemocracy#122 from democrateam/poll_results_…
Browse files Browse the repository at this point in the history
…button

Change poll button if results are enabled
  • Loading branch information
decabeza committed Dec 27, 2022
2 parents 1c7624e + 2f8ac01 commit e9e6806
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
8 changes: 4 additions & 4 deletions app/helpers/polls_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ 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)
def link_to_poll(text, poll, css_class = "")
if can?(:results, poll)
link_to text, results_poll_path(id: poll.slug || poll.id)
link_to text, results_poll_path(id: poll.slug || poll.id), class: css_class
elsif can?(:stats, poll)
link_to text, stats_poll_path(id: poll.slug || poll.id)
link_to text, stats_poll_path(id: poll.slug || poll.id), class: css_class
else
link_to text, poll_path(id: poll.slug || poll.id)
link_to text, poll_path(id: poll.slug || poll.id), class: css_class
end
end

Expand Down
10 changes: 4 additions & 6 deletions app/views/custom/polls/_poll_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@
days: distance_of_time_in_words(Time.current, poll.ends_at + 1.day))) %>
</p>
<% end %>
<%= link_to poll_path(id: poll.slug || poll.id), class: "button expanded" do %>
<% if poll.expired? %>
<%= t("polls.index.participate_button_expired") %>
<% else %>
<%= t("polls.index.participate_button") %>
<% end %>
<% if poll.expired? %>
<%= link_to_poll t("polls.index.participate_button_expired"), poll, "button expanded" %>
<% else %>
<%= link_to_poll t("polls.index.participate_button"), poll, "button expanded" %>
<% end %>
</div>
</div>
Expand Down
10 changes: 4 additions & 6 deletions app/views/polls/_poll_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@
<%= sanitize(t("polls.index.remaining",
days: distance_of_time_in_words(Time.current, poll.ends_at))) %>
</p>
<%= link_to poll_path(id: poll.slug || poll.id), class: "button expanded" do %>
<% if poll.expired? %>
<%= t("polls.index.participate_button_expired") %>
<% else %>
<%= t("polls.index.participate_button") %>
<% end %>
<% if poll.expired? %>
<%= link_to_poll t("polls.index.participate_button_expired"), poll, "button expanded" %>
<% else %>
<%= link_to_poll t("polls.index.participate_button"), poll, "button expanded" %>
<% end %>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions spec/system/polls/polls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,22 @@
expect(page).to have_content("You already have participated in this poll")
end

scenario "Poll title link to stats if enabled" do
scenario "Poll title and button link to stats if enabled" do
poll = create(:poll, :expired, name: "Poll with stats", stats_enabled: true)

visit polls_path(filter: "expired")

expect(page).to have_link("Poll with stats", href: stats_poll_path(poll.slug))
expect(page).to have_link("Poll ended", href: stats_poll_path(poll.slug))
end

scenario "Poll title link to results if enabled" do
scenario "Poll title and button link to results if enabled" do
poll = create(:poll, :expired, name: "Poll with results", stats_enabled: true, results_enabled: true)

visit polls_path(filter: "expired")

expect(page).to have_link("Poll with results", href: results_poll_path(poll.slug))
expect(page).to have_link("Poll ended", href: results_poll_path(poll.slug))
end

scenario "Shows SDG tags when feature is enabled" do
Expand Down

0 comments on commit e9e6806

Please sign in to comment.