Skip to content

Commit

Permalink
Merge pull request democrateam#96 from StemvanGroningen/polls_message
Browse files Browse the repository at this point in the history
Hide remaining days message on expired polls
  • Loading branch information
decabeza committed Dec 15, 2020
2 parents 164bb8c + 9811755 commit 66e99c2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
42 changes: 23 additions & 19 deletions app/views/custom/polls/_poll_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,33 @@
<%= t("polls.index.not_logged_in") %>
</div>
<% elsif user_signed_in? %>
<% if current_user.unverified? %>
<div class="callout warning">
<span class="fas fa-user"></span>
<%= t("polls.index.unverified") %>
</div>
<% elsif cannot?(:answer, poll) %>
<div class="callout warning">
<span class="fas fa-globe"></span>
<%= t("polls.index.cant_answer") %>
</div>
<% elsif !poll.votable_by?(current_user) %>
<div class="callout success">
<span class="far fa-check-circle"></span>
<%= t("polls.index.already_answer") %>
</div>
<% unless poll.expired? %>
<% if current_user.unverified? %>
<div class="callout warning">
<span class="fas fa-user"></span>
<%= t("polls.index.unverified") %>
</div>
<% elsif cannot?(:answer, poll) %>
<div class="callout warning">
<span class="fas fa-globe"></span>
<%= t("polls.index.cant_answer") %>
</div>
<% elsif !poll.votable_by?(current_user) %>
<div class="callout success">
<span class="far fa-check-circle"></span>
<%= t("polls.index.already_answer") %>
</div>
<% end %>
<% end %>
<% end %>
</div>
<div class="table-cell align-bottom">
<p class="small text-right">
<%= sanitize(t("polls.index.remaining",
days: distance_of_time_in_words(Time.current, poll.ends_at))) %>
</p>
<% unless poll.expired? %>
<p class="small text-right">
<%= sanitize(t("polls.index.remaining",
days: distance_of_time_in_words(Time.current, poll.ends_at))) %>
</p>
<% end %>
<%= link_to poll_path(id: poll.slug || poll.id), class: "button expanded" do %>
<% if poll.expired? %>
<%= t("polls.index.participate_button_expired") %>
Expand Down
23 changes: 19 additions & 4 deletions spec/features/polls/polls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,24 @@
expect(page).to have_content("Question 2 #{question2.title}")
end

scenario "Polls display remaining days to participate" do
scenario "Polls display remaining days to participate if not expired" do
travel_to "10/06/2020".to_date
create(:poll, starts_at: "01/06/2020", ends_at: "20/06/2020")
create(:poll, starts_at: "01/05/2020", ends_at: "31/05/2020", name: "Expired poll")
create(:poll, starts_at: "01/06/2020", ends_at: "20/06/2020", name: "Active poll")

visit polls_path

within(".poll") do
expect(page).to have_content("Remaining 10 days to participate")
end

click_link "Expired"

within(".poll") do
expect(page).not_to have_content("Remaining")
expect(page).not_to have_content("days to participate")
end

travel_back
end

Expand Down Expand Up @@ -93,19 +102,25 @@

scenario "Displays icon correctly", :js do
create_list(:poll, 3)
create(:poll, :expired, name: "Expired poll")

visit polls_path

expect(page).to have_css(".message .callout .fa-user", count: 3)
expect(page).to have_content("You must sign in or sign up to participate")
expect(page).to have_content("You must sign in or sign up to participate", count: 3)

user = create(:user)
login_as(user)

visit polls_path

expect(page).to have_css(".message .callout .fa-user", count: 3)
expect(page).to have_content("You must verify your account to participate")
expect(page).to have_content("You must verify your account to participate", count: 3)

click_link "Expired"

expect(page).not_to have_css(".message .callout .fa-user")
expect(page).not_to have_content("You must verify your account to participate")
end

scenario "Geozone poll" do
Expand Down

0 comments on commit 66e99c2

Please sign in to comment.