Merge pull request #5744 from consuldemocracy/select_name

Associate all select fields with labels
This commit is contained in:
Javi Martín
2024-11-12 16:22:37 +01:00
committed by GitHub
37 changed files with 188 additions and 208 deletions

View File

@@ -1,17 +1,17 @@
(function() {
"use strict";
App.PollsAdmin = {
App.AdminPollShiftsForm = {
initialize: function() {
$("select[class='js-poll-shifts']").on({
change: function() {
switch ($(this).val()) {
case "vote_collection":
$("select[class='js-shift-vote-collection-dates']").show();
$("select[class='js-shift-recount-scrutiny-dates']").hide();
$(".js-shift-vote-collection-dates").show();
$(".js-shift-recount-scrutiny-dates").hide();
break;
case "recount_scrutiny":
$("select[class='js-shift-recount-scrutiny-dates']").show();
$("select[class='js-shift-vote-collection-dates']").hide();
$(".js-shift-recount-scrutiny-dates").show();
$(".js-shift-vote-collection-dates").hide();
}
}
});

View File

@@ -101,7 +101,6 @@
//= require imageable
//= require tree_navigator
//= require tag_autocomplete
//= require polls_admin
//= require leaflet/dist/leaflet
//= require leaflet.markercluster/dist/leaflet.markercluster
//= require map
@@ -157,7 +156,6 @@ var initialize_modules = function() {
App.Documentable.initialize();
App.Imageable.initialize();
App.TagAutocomplete.initialize();
App.PollsAdmin.initialize();
App.Map.initialize();
App.Polls.initialize();
App.Sortable.initialize();
@@ -171,6 +169,7 @@ var initialize_modules = function() {
}
App.AdminBudgetsWizardCreationStep.initialize();
App.AdminMachineLearningScripts.initialize();
App.AdminPollShiftsForm.initialize();
App.AdminTenantsForm.initialize();
App.AdminVotationTypesFields.initialize();
App.AdminMenu.initialize();

View File

@@ -1,5 +1,5 @@
<%= form_for @shift, as: :shift, url: admin_booth_shifts_path do |f| %>
<%= render "shared/errors", resource: @shift %>
<%= form_for shift, as: :shift, url: admin_booth_shifts_path do |f| %>
<%= render "shared/errors", resource: shift %>
<fieldset class="fieldset">
<legend>
@@ -8,8 +8,8 @@
<div class="small-12 medium-3 column highlight padding">
<strong><%= t("admin.poll_shifts.new.officer") %></strong>
<br><%= @officer.name %>
<%= f.hidden_field :officer_id, value: @officer.id %>
<br><%= officer.name %>
<%= f.hidden_field :officer_id, value: officer.id %>
</div>
<div class="small-12 medium-3 column">
@@ -20,19 +20,26 @@
</div>
<div class="small-12 medium-3 column">
<label><%= t("admin.poll_shifts.new.date") %></label>
<%= label_tag :shift_date_vote_collection_date,
t("admin.poll_shifts.new.date"),
class: "js-shift-vote-collection-dates" %>
<%= select "shift[date]", "vote_collection_date",
options_for_select(shift_vote_collection_dates(@booth, @voting_polls)),
{ prompt: @voting_polls.present? ? t("admin.poll_shifts.new.select_date") : t("admin.poll_shifts.new.no_voting_days") },
options_for_select(shift_vote_collection_dates),
{ prompt: voting_polls.present? ? t("admin.poll_shifts.new.select_date") : t("admin.poll_shifts.new.no_voting_days") },
class: "js-shift-vote-collection-dates" %>
<%= label_tag :shift_date_recount_scrutiny_date,
t("admin.poll_shifts.new.date"),
class: "js-shift-recount-scrutiny-dates",
hidden: "hidden" %>
<%= select "shift[date]", "recount_scrutiny_date",
options_for_select(shift_recount_scrutiny_dates(@booth, @recount_polls)),
options_for_select(shift_recount_scrutiny_dates),
{ prompt: t("admin.poll_shifts.new.select_date") },
class: "js-shift-recount-scrutiny-dates",
hidden: "hidden" %>
</div>
<%= f.hidden_field :booth_id, value: @booth.id %>
<%= f.hidden_field :booth_id, value: booth.id %>
<div class="small-12 medium-3 column">
<%= f.submit t("admin.poll_shifts.new.add_shift"),

View File

@@ -0,0 +1,56 @@
class Admin::Poll::Shifts::FormComponent < ApplicationComponent
attr_reader :shift, :booth, :officer
def initialize(shift, booth:, officer:)
@shift = shift
@booth = booth
@officer = officer
end
private
def voting_polls
booth.polls.current
end
def recount_polls
booth.polls.current_or_recounting
end
def shift_vote_collection_dates
return [] if voting_polls.blank?
date_options((voting_start_date..voting_end_date), Poll::Shift.tasks[:vote_collection])
end
def shift_recount_scrutiny_dates
return [] if recount_polls.blank?
dates = recount_polls.map(&:ends_at).map(&:to_date).sort.reduce([]) do |total, date|
initial_date = [date, Date.current].max
total << (initial_date..date + Poll::RECOUNT_DURATION).to_a
end
date_options(dates.flatten.uniq, Poll::Shift.tasks[:recount_scrutiny])
end
def date_options(dates, task_id)
valid_dates(dates, task_id).map { |date| [l(date, format: :long), l(date)] }
end
def valid_dates(dates, task_id)
dates.reject { |date| officer_shifts(task_id).include?(date) }
end
def voting_start_date
start_date = voting_polls.minimum(:starts_at).to_date
[start_date, Date.current].max
end
def voting_end_date
voting_polls.maximum(:ends_at).to_date
end
def officer_shifts(task_id)
officer.shifts.where(task: task_id, booth: booth).map(&:date)
end
end

View File

@@ -0,0 +1 @@
<%= form.date_field :date_of_birth, **field_options %>

View File

@@ -0,0 +1,25 @@
class Shared::DateOfBirthFieldComponent < ApplicationComponent
attr_reader :form, :options
def initialize(form, **options)
@form = form
@options = options
end
private
def default_options
{
min: "1900-01-01",
max: minimum_required_age.years.ago
}
end
def field_options
default_options.merge(options)
end
def minimum_required_age
User.minimum_required_age
end
end

View File

@@ -5,8 +5,6 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController
def new
load_shifts
@shift = ::Poll::Shift.new
@voting_polls = @booth.polls.current
@recount_polls = @booth.polls.current_or_recounting
end
def create

View File

@@ -1,44 +0,0 @@
module ShiftsHelper
def shift_vote_collection_dates(booth, polls)
return [] if polls.blank?
date_options((start_date(polls)..end_date(polls)), Poll::Shift.tasks[:vote_collection], booth)
end
def shift_recount_scrutiny_dates(booth, polls)
return [] if polls.blank?
dates = polls.map(&:ends_at).map(&:to_date).sort.reduce([]) do |total, date|
initial_date = [date, Date.current].max
total << (initial_date..date + Poll::RECOUNT_DURATION).to_a
end
date_options(dates.flatten.uniq, Poll::Shift.tasks[:recount_scrutiny], booth)
end
def date_options(dates, task_id, booth)
valid_dates(dates, task_id, booth).map { |date| [l(date, format: :long), l(date)] }
end
def valid_dates(dates, task_id, booth)
dates.reject { |date| officer_shifts(task_id, booth).include?(date) }
end
def start_date(polls)
start_date = polls.minimum(:starts_at).to_date
[start_date, Date.current].max
end
def end_date(polls)
polls.maximum(:ends_at).to_date
end
def officer_select_options(officers)
officers.map { |officer| [officer.name, officer.id] }
end
private
def officer_shifts(task_id, booth)
@officer.shifts.where(task: task_id, booth: booth).map(&:date)
end
end

View File

@@ -5,10 +5,6 @@ module VerificationHelper
[t("verification.residence.new.document_type.residence_card"), 3]]
end
def minimum_required_age
(Setting["min_age_to_participate"] || 16).to_i
end
def mask_phone(number)
match = number.match(/\d{3}$/)
"******#{match}"

View File

@@ -1,13 +0,0 @@
module ActiveModel::Dates
def parse_date(field, attrs)
year, month, day = attrs["#{field}(1i)"], attrs["#{field}(2i)"], attrs["#{field}(3i)"]
return nil if day.blank? || month.blank? || year.blank?
Date.new(year.to_i, month.to_i, day.to_i)
end
def remove_date(field, attrs)
attrs.except("#{field}(1i)", "#{field}(2i)", "#{field}(3i)")
end
end

View File

@@ -1,10 +1,10 @@
class Officing::Residence
include ActiveModel::Model
include ActiveModel::Dates
include ActiveModel::Attributes
include ActiveModel::Validations::Callbacks
attr_accessor :user, :officer, :document_number, :document_type, :year_of_birth,
:date_of_birth, :postal_code
attribute :date_of_birth, :date
attr_accessor :user, :officer, :document_number, :document_type, :year_of_birth, :postal_code
before_validation :retrieve_census_data
@@ -18,8 +18,6 @@ class Officing::Residence
validate :local_residence
def initialize(attrs = {})
self.date_of_birth = parse_date("date_of_birth", attrs)
attrs = remove_date("date_of_birth", attrs)
super
clean_document_number
end

View File

@@ -1,8 +1,9 @@
class Verification::Management::Document
include ActiveModel::Model
include ActiveModel::Dates
include ActiveModel::Attributes
attr_accessor :document_type, :document_number, :date_of_birth, :postal_code
attribute :date_of_birth, :date
attr_accessor :document_type, :document_number, :postal_code
validates :document_type, :document_number, presence: true
validates :date_of_birth, presence: true, if: -> { Setting.force_presence_date_of_birth? }
@@ -10,12 +11,6 @@ class Verification::Management::Document
delegate :username, :email, to: :user, allow_nil: true
def initialize(attrs = {})
self.date_of_birth = parse_date("date_of_birth", attrs)
attrs = remove_date("date_of_birth", attrs)
super
end
def user
@user = User.active.by_document(document_type, document_number).first
end

View File

@@ -1,9 +1,10 @@
class Verification::Residence
include ActiveModel::Model
include ActiveModel::Dates
include ActiveModel::Attributes
include ActiveModel::Validations::Callbacks
attr_accessor :user, :document_number, :document_type, :date_of_birth, :postal_code, :terms_of_service
attribute :date_of_birth, :date
attr_accessor :user, :document_number, :document_type, :postal_code, :terms_of_service
validates :document_number, presence: true
validates :document_type, presence: true
@@ -18,8 +19,6 @@ class Verification::Residence
validate :local_residence
def initialize(attrs = {})
self.date_of_birth = parse_date("date_of_birth", attrs)
attrs = remove_date("date_of_birth", attrs)
super
clean_document_number
end

View File

@@ -5,7 +5,7 @@
method: :get,
id: "admin_download_emails" do %>
<label><%= t("admin.emails_download.index.download_segment") %></label>
<%= label_tag :users_segment, t("admin.emails_download.index.download_segment") %>
<p class="help-text" id="emails-help-text">
<%= t("admin.emails_download.index.download_segment_help_text") %>
</p>

View File

@@ -15,9 +15,7 @@
<div class="row">
<div class="date-of-birth small-12">
<%= f.date_select :date_of_birth,
prompt: true,
start_year: 1900, end_year: minimum_required_age.years.ago.year %>
<%= render Shared::DateOfBirthFieldComponent.new(f) %>
</div>
</div>

View File

@@ -8,7 +8,7 @@
</p>
<%= render "search_officers" %>
<% else %>
<%= render "form" %>
<%= render Admin::Poll::Shifts::FormComponent.new(@shift, booth: @booth, officer: @officer) %>
<% end %>
<div id="shifts">

View File

@@ -17,9 +17,7 @@
<% if Setting.force_presence_date_of_birth? %>
<div class="date-of-birth small-12 medium-5">
<%= f.date_select :date_of_birth,
prompt: true,
start_year: 1900, end_year: minimum_required_age.years.ago.year %>
<%= render Shared::DateOfBirthFieldComponent.new(f) %>
</div>
<% end %>

View File

@@ -11,10 +11,7 @@
<%= f.text_field :email,
label: t("management.users.email_optional_label") %>
<div class="date-of-birth">
<%= f.date_select :date_of_birth,
prompt: true,
start_year: 1900, end_year: 16.years.ago.year,
label: t("management.date_of_birth") %>
<%= render Shared::DateOfBirthFieldComponent.new(f, label: t("management.date_of_birth")) %>
</div>
<%= f.submit t("management.users.create_user_submit"), class: "button success" %>
<% end %>

View File

@@ -12,9 +12,8 @@
<div class="small-12 column">
<%= f.select :id,
@booths.map { |booth| [booth.location, booth.id] },
selected: @booths.first,
label: false,
tabindex: "1" %>
{ selected: @booths.first, label: false },
{ "aria-label": t("officing.booth.new.title") } %>
<%= f.submit(t("devise_views.sessions.new.submit"), class: "button expanded") %>
</div>

View File

@@ -14,9 +14,7 @@
<% if Setting.force_presence_date_of_birth? %>
<div class="date-of-birth small-12 medium-6 clear">
<%= f.date_select :date_of_birth,
prompt: true,
start_year: 1900, end_year: minimum_required_age.years.ago.year %>
<%= render Shared::DateOfBirthFieldComponent.new(f) %>
</div>
<% else %>
<div class="date-of-birth small-12 medium-6">

View File

@@ -4,7 +4,7 @@
<%= form_tag(officing_poll_results_path(@poll), { id: "officer_assignment_form" }) do %>
<div class="row">
<div class="small-12 medium-6 column">
<label><%= t("officing.results.new.booth") %></label>
<%= label_tag :officer_assignment_id, t("officing.results.new.booth") %>
<%= select_tag :officer_assignment_id,
booths_for_officer_select_options(@officer_assignments),
{ prompt: t("officing.results.new.select_booth") } %>

View File

@@ -57,9 +57,7 @@
</div>
<div class="date-of-birth small-12 medium-6 clear">
<%= f.date_select :date_of_birth,
prompt: true,
start_year: 1900, end_year: minimum_required_age.years.ago.year %>
<%= render Shared::DateOfBirthFieldComponent.new(f) %>
</div>
<div class="small-12 medium-5 clear">

View File

@@ -0,0 +1,26 @@
require "rails_helper"
describe Shared::DateOfBirthFieldComponent do
before do
dummy_model = Class.new do
include ActiveModel::Model
attr_accessor :date_of_birth
end
stub_const("DummyModel", dummy_model)
end
let(:form) { ConsulFormBuilder.new(:dummy, DummyModel.new, ApplicationController.new.view_context, {}) }
let(:component) { Shared::DateOfBirthFieldComponent.new(form) }
it "uses the minimum required age as the latest date by default" do
Setting["min_age_to_participate"] = 13
travel_to "2015-07-15" do
render_inline component
expect(page).to have_field "Date of birth"
expect(page).to have_css "input[type=date][min='1900-01-01'][max='2002-07-15']"
end
end
end

View File

@@ -84,18 +84,14 @@ describe Officing::Residence do
describe "dates" do
it "is not valid but not because date of birth" do
custom_residence = Officing::Residence.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1",
"date_of_birth(1i)" => "1980")
custom_residence = Officing::Residence.new(date_of_birth: "1980-01-01")
expect(custom_residence).not_to be_valid
expect(custom_residence.errors[:date_of_birth]).to be_empty
end
it "is not valid without a date of birth" do
custom_residence = Officing::Residence.new("date_of_birth(3i)" => "",
"date_of_birth(2i)" => "",
"date_of_birth(1i)" => "")
custom_residence = Officing::Residence.new(date_of_birth: "")
expect(custom_residence).not_to be_valid
expect(custom_residence.errors[:date_of_birth]).to include("can't be blank")
end

View File

@@ -57,17 +57,13 @@ describe Verification::Management::Document do
describe "dates" do
it "is valid with a valid date of birth" do
verification_document = Verification::Management::Document.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1",
"date_of_birth(1i)" => "1980")
verification_document = Verification::Management::Document.new(date_of_birth: "1980-01-01")
expect(verification_document.errors[:date_of_birth]).to be_empty
end
it "is not valid without a date of birth" do
verification_document = Verification::Management::Document.new("date_of_birth(3i)" => "",
"date_of_birth(2i)" => "",
"date_of_birth(1i)" => "")
verification_document = Verification::Management::Document.new(date_of_birth: "")
expect(verification_document).not_to be_valid
expect(verification_document.errors[:date_of_birth]).to include("can't be blank")
end

View File

@@ -11,26 +11,20 @@ describe Verification::Residence do
describe "dates" do
it "is valid with a valid date of birth" do
residence = Verification::Residence.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1",
"date_of_birth(1i)" => "1980")
residence = Verification::Residence.new(date_of_birth: "1980-01-01")
expect(residence.errors[:date_of_birth]).to be_empty
end
it "is not valid without a date of birth" do
residence = Verification::Residence.new("date_of_birth(3i)" => "",
"date_of_birth(2i)" => "",
"date_of_birth(1i)" => "")
residence = Verification::Residence.new(date_of_birth: "")
expect(residence).not_to be_valid
expect(residence.errors[:date_of_birth]).to include("can't be blank")
end
end
it "validates user has allowed age" do
residence = Verification::Residence.new("date_of_birth(3i)" => "1",
"date_of_birth(2i)" => "1",
"date_of_birth(1i)" => 5.years.ago.year.to_s)
residence = Verification::Residence.new(date_of_birth: 5.years.ago)
expect(residence).not_to be_valid
expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate")
end

View File

@@ -1,17 +1,8 @@
module Verifications
def select_date(values, selector)
selector = selector[:from]
day, month, year = values.split("-")
select day, from: "#{selector}_3i"
select month, from: "#{selector}_2i"
select year, from: "#{selector}_1i"
end
def verify_residence
select "DNI", from: "residence_document_type"
fill_in "residence_document_number", with: "12345678Z"
select_date "31-#{I18n.l(Date.current.at_end_of_year, format: "%B")}-1980",
from: "residence_date_of_birth"
fill_in "residence_date_of_birth", with: Date.new(1980, 12, 31)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"

View File

@@ -26,7 +26,7 @@ describe "Admin download user emails" do
visit admin_emails_download_index_path
within("#admin_download_emails") do
select "Administrators", from: "users_segment"
select "Administrators", from: "Download email addresses"
click_button "Download emails list"
end

View File

@@ -84,9 +84,7 @@ describe "Admin local census records", :admin do
select "DNI", from: :local_census_record_document_type
fill_in :local_census_record_document_number, with: "#DOCUMENT"
select "1982", from: :local_census_record_date_of_birth_1i
select "July", from: :local_census_record_date_of_birth_2i
select "7", from: :local_census_record_date_of_birth_3i
fill_in "Date of birth", with: Date.new(1982, 7, 7)
fill_in :local_census_record_postal_code, with: "07003"
click_button "Save"
@@ -116,9 +114,7 @@ describe "Admin local census records", :admin do
select "Passport", from: :local_census_record_document_type
fill_in :local_census_record_document_number, with: "#NIE_NUMBER"
select "1982", from: :local_census_record_date_of_birth_1i
select "August", from: :local_census_record_date_of_birth_2i
select "8", from: :local_census_record_date_of_birth_3i
fill_in "Date of birth", with: Date.new(1982, 8, 8)
fill_in :local_census_record_postal_code, with: "07007"
click_button "Save"

View File

@@ -53,10 +53,10 @@ describe "Admin shifts", :admin do
click_button "Search"
click_link "Edit shifts"
expect(page).to have_select("shift_date_vote_collection_date",
options: ["Select day", *vote_collection_dates])
expect(page).not_to have_select("shift_date_recount_scrutiny_date")
select I18n.l(Date.current, format: :long), from: "shift_date_vote_collection_date"
expect(page).to have_select "Date", options: ["Select day", *vote_collection_dates]
expect(page).not_to have_select with_options: recount_scrutiny_dates
select I18n.l(Date.current, format: :long), from: "Date"
click_button "Add shift"
expect(page).to have_content "Shift added"
@@ -82,10 +82,9 @@ describe "Admin shifts", :admin do
select "Recount & Scrutiny", from: "shift_task"
expect(page).to have_select("shift_date_recount_scrutiny_date",
options: ["Select day", *recount_scrutiny_dates])
expect(page).not_to have_select("shift_date_vote_collection_date")
select I18n.l(poll.ends_at.to_date + 4.days, format: :long), from: "shift_date_recount_scrutiny_date"
expect(page).to have_select "Date", options: ["Select day", *recount_scrutiny_dates]
expect(page).not_to have_select with_options: vote_collection_dates
select I18n.l(poll.ends_at.to_date + 4.days, format: :long), from: "Date"
click_button "Add shift"
expect(page).to have_content "Shift added"
@@ -126,11 +125,9 @@ describe "Admin shifts", :admin do
click_button "Search"
click_link "Edit shifts"
expect(page).to have_select("shift_date_vote_collection_date",
options: ["Select day", *vote_collection_dates])
expect(page).to have_select "Date", options: ["Select day", *vote_collection_dates]
select "Recount & Scrutiny", from: "shift_task"
expect(page).to have_select("shift_date_recount_scrutiny_date",
options: ["Select day", *recount_scrutiny_dates])
expect(page).to have_select "Date", options: ["Select day", *recount_scrutiny_dates]
end
scenario "Change option from Recount & Scrutinity to Collect Votes" do
@@ -144,11 +141,11 @@ describe "Admin shifts", :admin do
select "Recount & Scrutiny", from: "shift_task"
expect(page).to have_select("shift_date_recount_scrutiny_date", options: ["Select day"])
expect(page).to have_select "Date", options: ["Select day"]
select "Collect Votes", from: "shift_task"
expect(page).to have_select("shift_date_vote_collection_date", options: ["Voting days ended"])
expect(page).to have_select "Date", options: ["Voting days ended"]
end
scenario "Error on create" do

View File

@@ -103,7 +103,7 @@ describe "Poll budget ballot sheets" do
scenario "Ballot sheet is saved" do
visit new_officing_poll_ballot_sheet_path(poll)
select booth.name, from: "officer_assignment_id"
select booth.name, from: "Booth"
fill_in "data", with: "1234;5678"
click_button "Save"
@@ -119,7 +119,7 @@ describe "Poll budget ballot sheets" do
scenario "Ballot sheet is not saved" do
visit new_officing_poll_ballot_sheet_path(poll)
select booth.name, from: "officer_assignment_id"
select booth.name, from: "Booth"
click_button "Save"
expect(page).to have_content("CSV data can't be blank")

View File

@@ -63,7 +63,7 @@ describe "DocumentVerifications" do
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
select_date "31-December-1980", from: "document_verification_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "document_verification_postal_code", with: "inexisting"
click_button "Check document"
@@ -77,7 +77,7 @@ describe "DocumentVerifications" do
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
select_date "31-December-1980", from: "document_verification_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "document_verification_postal_code", with: "28013"
click_button "Check document"

View File

@@ -13,7 +13,7 @@ describe "Users" do
fill_in "user_username", with: "pepe"
fill_in "user_email", with: "pepe@gmail.com"
select_date "31-December-1980", from: "user_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
click_button "Create user"
@@ -54,7 +54,7 @@ describe "Users" do
fill_in "user_username", with: "Kelly Sue"
fill_in "user_email", with: ""
select_date "31-December-1980", from: "user_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
click_button "Create user"

View File

@@ -47,7 +47,7 @@ describe "Booth", :with_frozen_time do
expect(page).to have_content "Choose your booth"
select booth2.location, from: "booth_id"
select booth2.location, from: "Choose your booth"
click_button "Enter"
within("#officing-booth") do
@@ -72,6 +72,6 @@ describe "Booth", :with_frozen_time do
expect(page).to have_content "Choose your booth"
expect(page).to have_select("booth_id", options: [booth1.location, booth2.location])
expect(page).to have_select "Choose your booth", options: [booth1.location, booth2.location]
end
end

View File

@@ -162,7 +162,7 @@ describe "Residence", :with_frozen_time do
select "DNI", from: "residence_document_type"
fill_in "residence_document_number", with: "12345678Z"
select_date "31-December-1980", from: "residence_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "residence_postal_code", with: "28013"
click_button "Validate document"

View File

@@ -57,7 +57,7 @@ describe "Officing Results", :with_frozen_time do
expect(page).not_to have_content("Your results")
select booth.name, from: "officer_assignment_id"
select booth.name, from: "Booth"
fill_in "questions[#{question_1.id}][0]", with: "100"
fill_in "questions[#{question_1.id}][1]", with: "200"
@@ -100,7 +100,7 @@ describe "Officing Results", :with_frozen_time do
visit new_officing_poll_result_path(poll)
booth_name = partial_result.booth_assignment.booth.name
select booth_name, from: "officer_assignment_id"
select booth_name, from: "Booth"
fill_in "questions[#{question_1.id}][0]", with: "5555"
fill_in "questions[#{question_1.id}][1]", with: "200"

View File

@@ -12,7 +12,7 @@ describe "Residence" do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select_date "31-December-1980", from: "residence_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"
click_button "Verify residence"
@@ -30,7 +30,7 @@ describe "Residence" do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select_date "31-December-1980", from: "residence_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"
click_button "Verify residence"
@@ -38,21 +38,6 @@ describe "Residence" do
expect(page).to have_content "Residence verified"
end
scenario "Residence form use min age to participate" do
min_age = (Setting["min_age_to_participate"] = 16).to_i
underage = min_age - 1
user = create(:user)
login_as(user)
visit account_path
click_link "Verify my account"
expect(page).to have_select("residence_date_of_birth_1i",
with_options: [min_age.years.ago.year])
expect(page).not_to have_select("residence_date_of_birth_1i",
with_options: [underage.years.ago.year])
end
scenario "When trying to verify a deregistered account old votes are reassigned" do
erased_user = create(:user, document_number: "12345678Z", document_type: "1", erased_at: Time.current)
vote = create(:vote, voter: erased_user)
@@ -65,7 +50,7 @@ describe "Residence" do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select_date "31-December-1980", from: "residence_date_of_birth"
fill_in "Date of birth", with: Date.new(1980, 12, 31)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"
@@ -100,9 +85,7 @@ describe "Residence" do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select "1997", from: "residence_date_of_birth_1i"
select "January", from: "residence_date_of_birth_2i"
select "1", from: "residence_date_of_birth_3i"
fill_in "Date of birth", with: Date.new(1997, 1, 1)
fill_in "residence_postal_code", with: "00000"
check "residence_terms_of_service"
@@ -120,9 +103,7 @@ describe "Residence" do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select "1997", from: "residence_date_of_birth_1i"
select "January", from: "residence_date_of_birth_2i"
select "1", from: "residence_date_of_birth_3i"
fill_in "Date of birth", with: Date.new(1997, 1, 1)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"
@@ -141,9 +122,7 @@ describe "Residence" do
5.times do
fill_in "Document number", with: "12345678Z"
select "DNI", from: "residence_document_type"
select "1997", from: "residence_date_of_birth_1i"
select "January", from: "residence_date_of_birth_2i"
select "1", from: "residence_date_of_birth_3i"
fill_in "Date of birth", with: Date.new(1997, 1, 1)
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"