diff --git a/app/models/verification/management/document.rb b/app/models/verification/management/document.rb index 17ea065bd..4264154d3 100644 --- a/app/models/verification/management/document.rb +++ b/app/models/verification/management/document.rb @@ -23,7 +23,7 @@ class Verification::Management::Document end def valid_age?(response) - if under_sixteen?(response) + if under_age?(response) errors.add(:age, true) return false else @@ -31,8 +31,8 @@ class Verification::Management::Document end end - def under_sixteen?(response) - 16.years.ago.beginning_of_day < response.date_of_birth.beginning_of_day + def under_age?(response) + User.minimum_required_age.years.ago.beginning_of_day < response.date_of_birth.beginning_of_day end def verified? diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index 96a36e5cd..eda562671 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -36,7 +36,7 @@ class Verification::Residence def allowed_age return if errors[:date_of_birth].any? - errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless self.date_of_birth <= 16.years.ago + errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless self.date_of_birth <= User.minimum_required_age.years.ago end def document_number_uniqueness diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 636e42349..25032010e 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -29,7 +29,7 @@ en: not_in_census_info: 'Citizens not in the Census can participate in the website with the following permissions:' please_check_account_data: Please check that the account data above are correct. title: User management - under_age: You must be over 16 to verify your account. + under_age: "You don't have the required age to verify your account." verify: Verify email_label: Email email_verifications: diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index f4ada5c9e..9ac276f3a 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -29,7 +29,7 @@ es: not_in_census_info: 'Las personas no empadronadas pueden participar en el Portal de Gobierno Abierto con las siguientes posibilidades:' please_check_account_data: Compruebe que los datos anteriores son correctos para proceder a verificar la cuenta completamente. title: Gestión de usuarios - under_age: Debes ser mayor de 16 años para verificar tu cuenta. + under_age: No tienes edad suficiente para verificar tu cuenta. verify: Verificar usuario email_label: Email email_verifications: diff --git a/config/locales/verification.en.yml b/config/locales/verification.en.yml index b6a89f939..598532354 100755 --- a/config/locales/verification.en.yml +++ b/config/locales/verification.en.yml @@ -59,7 +59,7 @@ en: residence_card: Residence card spanish_id: DNI document_type_label: Document type - error_not_allowed_age: You must be at least 16 years old + error_not_allowed_age: You don't have the required age to participate error_not_allowed_postal_code: In order to be verified, you must be registered. error_verifying_census: The Census was unable to verify your information. Please confirm that your census details are correct by calling to City Council or visit one %{offices}. error_verifying_census_offices: Citizen Support Office diff --git a/config/locales/verification.es.yml b/config/locales/verification.es.yml index 65cfead6b..c08900cdf 100644 --- a/config/locales/verification.es.yml +++ b/config/locales/verification.es.yml @@ -59,7 +59,7 @@ es: residence_card: Tarjeta de residencia spanish_id: DNI document_type_label: Tipo de documento - error_not_allowed_age: Hay que tener al menos 16 años + error_not_allowed_age: No tienes la edad mínima para participar error_not_allowed_postal_code: Para verificarte debes estar empadronado. error_verifying_census: El Padrón no pudo verificar tu información. Por favor, confirma que tus datos de empadronamiento sean correctos llamando al Ayuntamiento o visitando una %{offices}. error_verifying_census_offices: oficina de Atención al ciudadano diff --git a/spec/features/management/document_verifications_spec.rb b/spec/features/management/document_verifications_spec.rb index 130630762..ebde442d8 100644 --- a/spec/features/management/document_verifications_spec.rb +++ b/spec/features/management/document_verifications_spec.rb @@ -63,13 +63,13 @@ feature 'DocumentVerifications' do end scenario 'User age is checked' do - expect_any_instance_of(Verification::Management::Document).to receive(:under_sixteen?).and_return(true) + expect_any_instance_of(Verification::Management::Document).to receive(:under_age?).and_return(true) visit management_document_verifications_path fill_in 'document_verification_document_number', with: '12345678Z' click_button 'Check' - expect(page).to have_content "You must be over 16 to verify your account." + expect(page).to have_content "You don't have the required age to verify your account." end end \ No newline at end of file diff --git a/spec/models/residence_spec.rb b/spec/models/residence_spec.rb index 968a80e62..6841f636b 100644 --- a/spec/models/residence_spec.rb +++ b/spec/models/residence_spec.rb @@ -27,7 +27,7 @@ describe Verification::Residence do it "should validate user has allowed age" do residence = Verification::Residence.new({"date_of_birth(3i)"=>"1", "date_of_birth(2i)"=>"1", "date_of_birth(1i)"=>"#{5.year.ago.year}"}) expect(residence).to_not be_valid - expect(residence.errors[:date_of_birth]).to include("You must be at least 16 years old") + expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate") end it "should validate uniquness of document_number" do diff --git a/spec/models/verification/management/document_spec.rb b/spec/models/verification/management/document_spec.rb index 35fd89855..07732e7de 100644 --- a/spec/models/verification/management/document_spec.rb +++ b/spec/models/verification/management/document_spec.rb @@ -18,20 +18,20 @@ describe Verification::Management::Document do end end - describe "#under_sixteen?" do - it "returns true when the user is younger than sixteen years old" do - census_response = double(date_of_birth: Date.new(16.years.ago.year, 12, 31)) - expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be true + describe "#under_age?" do + it "returns true when the user is younger than the user's minimum required age" do + census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 12, 31)) + expect(Verification::Management::Document.new.under_age?(census_response)).to be true end - it "returns false when the user is sixteen years old" do - census_response = double(date_of_birth: Date.new(16.years.ago.year, 16.years.ago.month, 16.years.ago.day)) - expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false + it "returns false when the user is user's minimum required age" do + census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, User.minimum_required_age.years.ago.month, User.minimum_required_age.years.ago.day)) + expect(Verification::Management::Document.new.under_age?(census_response)).to be false end - it "returns false when the user is older than sixteen years old" do - census_response = double(date_of_birth: Date.new(33.years.ago.year, 12, 31)) - expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false + it "returns false when the user is older than user's minimum required age" do + census_response = double(date_of_birth: Date.new((User.minimum_required_age + 10).years.ago.year, 12, 31)) + expect(Verification::Management::Document.new.under_age?(census_response)).to be false end end end