diff --git a/app/views/officing/results/new.html.erb b/app/views/officing/results/new.html.erb
index 45aa443a3..aba3e17da 100644
--- a/app/views/officing/results/new.html.erb
+++ b/app/views/officing/results/new.html.erb
@@ -4,7 +4,7 @@
<%= form_tag(officing_poll_results_path(@poll), { id: "officer_assignment_form" }) do %>
-
+ <%= 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") } %>
diff --git a/app/views/verification/residence/new.html.erb b/app/views/verification/residence/new.html.erb
index c361d7d4c..9909d41af 100644
--- a/app/views/verification/residence/new.html.erb
+++ b/app/views/verification/residence/new.html.erb
@@ -57,9 +57,7 @@
- <%= f.date_select :date_of_birth,
- prompt: true,
- start_year: 1900, end_year: minimum_required_age.years.ago.year %>
+ <%= render Shared::DateOfBirthFieldComponent.new(f) %>
diff --git a/spec/components/shared/date_of_birth_field_component_spec.rb b/spec/components/shared/date_of_birth_field_component_spec.rb
new file mode 100644
index 000000000..403df8693
--- /dev/null
+++ b/spec/components/shared/date_of_birth_field_component_spec.rb
@@ -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
diff --git a/spec/models/officing/residence_spec.rb b/spec/models/officing/residence_spec.rb
index d30113111..c5049535a 100644
--- a/spec/models/officing/residence_spec.rb
+++ b/spec/models/officing/residence_spec.rb
@@ -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
diff --git a/spec/models/verification/management/document_spec.rb b/spec/models/verification/management/document_spec.rb
index 78d41c486..c089c5c3a 100644
--- a/spec/models/verification/management/document_spec.rb
+++ b/spec/models/verification/management/document_spec.rb
@@ -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
diff --git a/spec/models/verification/residence_spec.rb b/spec/models/verification/residence_spec.rb
index 988b2a805..a9df7bb8a 100644
--- a/spec/models/verification/residence_spec.rb
+++ b/spec/models/verification/residence_spec.rb
@@ -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
diff --git a/spec/support/common_actions/verifications.rb b/spec/support/common_actions/verifications.rb
index b6e65fae4..6dad2584c 100644
--- a/spec/support/common_actions/verifications.rb
+++ b/spec/support/common_actions/verifications.rb
@@ -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"
diff --git a/spec/system/admin/emails/emails_download_spec.rb b/spec/system/admin/emails/emails_download_spec.rb
index 7de835565..9e784cc05 100644
--- a/spec/system/admin/emails/emails_download_spec.rb
+++ b/spec/system/admin/emails/emails_download_spec.rb
@@ -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
diff --git a/spec/system/admin/local_census_records_spec.rb b/spec/system/admin/local_census_records_spec.rb
index 93bb19096..c40d926c7 100644
--- a/spec/system/admin/local_census_records_spec.rb
+++ b/spec/system/admin/local_census_records_spec.rb
@@ -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"
diff --git a/spec/system/admin/poll/shifts_spec.rb b/spec/system/admin/poll/shifts_spec.rb
index ad55359f8..841002c3d 100644
--- a/spec/system/admin/poll/shifts_spec.rb
+++ b/spec/system/admin/poll/shifts_spec.rb
@@ -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
diff --git a/spec/system/budget_polls/ballot_sheets_spec.rb b/spec/system/budget_polls/ballot_sheets_spec.rb
index 91c6aab56..931ce8d1c 100644
--- a/spec/system/budget_polls/ballot_sheets_spec.rb
+++ b/spec/system/budget_polls/ballot_sheets_spec.rb
@@ -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")
diff --git a/spec/system/management/document_verifications_spec.rb b/spec/system/management/document_verifications_spec.rb
index 2403bcd8a..328bc647f 100644
--- a/spec/system/management/document_verifications_spec.rb
+++ b/spec/system/management/document_verifications_spec.rb
@@ -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"
diff --git a/spec/system/management/users_spec.rb b/spec/system/management/users_spec.rb
index fccf14b29..ce8f0647b 100644
--- a/spec/system/management/users_spec.rb
+++ b/spec/system/management/users_spec.rb
@@ -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"
diff --git a/spec/system/officing/booth_spec.rb b/spec/system/officing/booth_spec.rb
index 2f86cbdd0..cf5b66aaa 100644
--- a/spec/system/officing/booth_spec.rb
+++ b/spec/system/officing/booth_spec.rb
@@ -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
diff --git a/spec/system/officing/residence_spec.rb b/spec/system/officing/residence_spec.rb
index 9ccee04ed..f1ee43f8c 100644
--- a/spec/system/officing/residence_spec.rb
+++ b/spec/system/officing/residence_spec.rb
@@ -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"
diff --git a/spec/system/officing/results_spec.rb b/spec/system/officing/results_spec.rb
index a3147093d..59abe9497 100644
--- a/spec/system/officing/results_spec.rb
+++ b/spec/system/officing/results_spec.rb
@@ -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"
diff --git a/spec/system/verification/residence_spec.rb b/spec/system/verification/residence_spec.rb
index a44d6e3ae..fa8850730 100644
--- a/spec/system/verification/residence_spec.rb
+++ b/spec/system/verification/residence_spec.rb
@@ -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"