From 0cf5299846ce095a2cae958532949019ba570009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 00:04:25 +0200 Subject: [PATCH 1/5] Set voting messages --- app/views/polls/questions/_answers.html.erb | 4 ++-- app/views/polls/show.html.erb | 5 +++++ config/locales/en/general.yml | 3 ++- config/locales/es/general.yml | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index 2bef6de72..ccc9f0322 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -2,8 +2,8 @@ <% if can? :answer, question %> <% question.question_answers.each do |answer| %> <% if @answers_by_question_id[question.id] == answer.title %> - "> + "> <%= answer.title %> <% else %> diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index b3a78e402..894899a72 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -38,6 +38,11 @@ <%= t("polls.show.already_voted_in_booth") %> <% else %> + <% if current_user && !@poll.votable_by?(current_user) %> +
+ <%= t("polls.show.already_voted_in_web") %> +
+ <% end %> <% @questions.each do |question| %> <%= render 'polls/questions/question', question: question %> <% end %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 1796049eb..473ac7391 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -481,7 +481,8 @@ en: help_text_1: "Voting takes place when a citizen proposal supports reaches 1% of the census with voting rights. Voting can also include questions that the City Council ask to the citizens decision." help_text_2: "To participate in the next vote you have to sign up on %{org} and verify your account. All registered voters in the city over 16 years old can vote. The results of all votes are binding on the government." show: - already_voted_in_booth: "You have already participated in a booth for this poll." + already_voted_in_booth: "You have already participated in a physical booth. You can not participate again." + already_voted_in_web: "You have already participated in this poll. If you vote again it will be overwritten." back: Back to voting cant_answer_not_logged_in: "You must %{signin} or %{signup} to participate." signin: Sign in diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index d5997e746..0af33da1d 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -481,7 +481,8 @@ es: help_text_1: "Las votaciones se convocan cuando una propuesta ciudadana alcanza el 1% de apoyos del censo con derecho a voto. En las votaciones también se pueden incluir cuestiones que el Ayuntamiento somete a decisión directa de la ciudadanía." help_text_2: "Para participar en la próxima votación tienes que registrarte en %{org} y verificar tu cuenta. Pueden votar todas las personas empadronadas en la ciudad mayores de 16 años. Los resultados de todas las votaciones serán vinculantes para el gobierno." show: - already_voted_in_booth: "Ya has participado en esta votación en una urna." + already_voted_in_booth: "Ya has participado en esta votación en urnas presenciales, no puedes volver a participar." + already_voted_in_web: "Ya has participado en esta votación. Si vuelves a votar se sobreescribirá tu resultado anterior." back: Volver a votaciones cant_answer_not_logged_in: "Necesitas %{signin} o %{signup} para participar." signin: iniciar sesión From c3f778bbdde2bc5c1c115e589d69142221cde40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 01:18:56 +0200 Subject: [PATCH 2/5] Check if user has voted before sign in --- app/helpers/polls_helper.rb | 4 ++++ app/views/polls/questions/_answers.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 27d33ea04..a676084cb 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -41,4 +41,8 @@ module PollsHelper booth.name + location end + def voted_before_sign_in(question) + current_user.current_sign_in_at >= question.poll.voters.find_by_user_id(current_user).updated_at + end + end diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index ccc9f0322..7fb4a5d71 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -1,7 +1,7 @@
<% if can? :answer, question %> <% question.question_answers.each do |answer| %> - <% if @answers_by_question_id[question.id] == answer.title %> + <% if @answers_by_question_id[question.id] == answer.title && !voted_before_sign_in(question) %> "> <%= answer.title %> From 8e5cf50679b3fa4e819d4d3e857dc37a33e7f68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 12:52:13 +0200 Subject: [PATCH 3/5] Prevent user from seeing its votes in a poll after signing in --- app/helpers/polls_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index a676084cb..c66db216f 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -42,7 +42,7 @@ module PollsHelper end def voted_before_sign_in(question) - current_user.current_sign_in_at >= question.poll.voters.find_by_user_id(current_user).updated_at + current_user.current_sign_in_at >= question.answers.find_or_initialize_by(author: current_user).updated_at end end From 089c1fecfd1187dc3b9e09de589bd567d85af6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 13:37:24 +0200 Subject: [PATCH 4/5] Added tests --- spec/features/polls/voter_spec.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 453924674..e558b7261 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -91,9 +91,32 @@ feature "Voter" do visit poll_path(poll) expect(page).to_not have_link('Yes') - expect(page).to have_content "You have already participated in a booth for this poll." + expect(page).to have_content "You have already participated in a physical booth. You can not participate again." expect(Poll::Voter.count).to eq(1) end + + scenario "Trying to vote in web again", :js do + login_as user + vote_for_poll_via_web(poll, question) + + visit poll_path(poll) + + expect(page).to have_content "You have already participated in this poll. If you vote again it will be overwritten." + within("#poll_question_#{question.id}_answers") do + expect(page).to_not have_link('Yes') + end + + click_link "Sign out" + + login_as user + visit poll_path(poll) + + within("#poll_question_#{question.id}_answers") do + expect(page).to have_link('Yes') + expect(page).to have_link('No') + end + + end end end From 305b5dcf07ddfab603b81679d27fc03ac34d28e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 14:45:44 +0200 Subject: [PATCH 5/5] Fixed test --- spec/features/polls/polls_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 22b90740a..c3211e1ab 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -209,8 +209,7 @@ feature 'Polls' do visit poll_path(poll) expect(page).to have_link('Han Solo') - expect(page).to_not have_link('Chewbacca') - expect(page).to have_content('Chewbacca') + expect(page).to have_link('Chewbacca') end scenario 'Level 2 users answering', :js do