diff --git a/app/views/polls/_poll_group.html.erb b/app/views/polls/_poll_group.html.erb index 7b5148263..e01320160 100644 --- a/app/views/polls/_poll_group.html.erb +++ b/app/views/polls/_poll_group.html.erb @@ -1,9 +1,23 @@ <% poll_group.each do |poll| %>
- <% if user_signed_in? && !current_user.unverified? && !poll.votable_by?(current_user) %> -
"> - <%= t("polls.index.already_answer") %> + <% if !user_signed_in? %> +
"> + <%= t("polls.index.not_logged_in") %>
+ <% elsif user_signed_in? %> + <% if current_user.unverified? %> +
"> + <%= t("polls.index.unverified") %> +
+ <% elsif cannot?(:answer, poll) %> +
"> + <%= t("polls.index.cant_answer") %> +
+ <% elsif !poll.votable_by?(current_user) %> +
"> + <%= t("polls.index.already_answer") %> +
+ <% end %> <% end %>
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index c407f8f39..5afd4a9cd 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -469,6 +469,9 @@ en: geozone_restricted: "Districts" geozone_info: "Can participate people in the Census of: " already_answer: "You already have participated in this poll" + not_logged_in: "You must sign in or sign up to participate" + unverified: "You must verify your account to participate" + cant_answer: "This poll is not available on your geozone" section_header: icon_alt: Voting icon title: Voting diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index f7b5e7fa2..02f60f8e6 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -469,6 +469,9 @@ es: geozone_restricted: "Distritos" geozone_info: 'Pueden participar las personas empadronadas en: ' already_answer: "Ya has participado en esta votación" + not_logged_in: "Necesitas iniciar sesión o registrarte para participar" + unverified: "Por favor verifica tu cuenta para participar" + cant_answer: "Esta votación no está disponible en tu zona" section_header: icon_alt: Icono de Votaciones title: Votaciones diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index a7a181623..a2e009f77 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -67,6 +67,43 @@ feature 'Polls' do expect(page).not_to have_link('Expired') end + scenario "Displays icon correctly", :js do + polls = create_list(:poll, 3) + + visit polls_path + + expect(page).to have_css(".not-logged-in", count: 3) + expect(page).to have_content("You must sign in or sign up to participate") + + user = create(:user) + login_as(user) + + visit polls_path + + expect(page).to have_css(".unverified", count: 3) + expect(page).to have_content("You must verify your account to participate") + + poll_district = create(:poll, geozone_restricted: true) + verified = create(:user, :level_two) + login_as(verified) + + visit polls_path + + expect(page).to have_css(".cant-answer", count: 1) + expect(page).to have_content("This poll is not available on your geozone") + + poll_with_question = create(:poll) + question = create(:poll_question, poll: poll_with_question) + answer1 = create(:poll_question_answer, question: question, title: 'Yes') + answer2 = create(:poll_question_answer, question: question, title: 'No') + vote_for_poll_via_web(poll_with_question, question, 'Yes') + + visit polls_path + + expect(page).to have_css(".already-answer", count: 1) + expect(page).to have_content("You already have participated in this poll") + end + scenario "Poll title link to stats if enabled" do poll = create(:poll, name: "Poll with stats", stats_enabled: true)