removes hardcoded age, favours setting

This commit is contained in:
Juanjo Bazán
2017-01-09 16:05:27 +01:00
parent 220e7397e1
commit e2118f701b
9 changed files with 21 additions and 21 deletions

View File

@@ -23,7 +23,7 @@ class Verification::Management::Document
end end
def valid_age?(response) def valid_age?(response)
if under_sixteen?(response) if under_age?(response)
errors.add(:age, true) errors.add(:age, true)
return false return false
else else
@@ -31,8 +31,8 @@ class Verification::Management::Document
end end
end end
def under_sixteen?(response) def under_age?(response)
16.years.ago.beginning_of_day < response.date_of_birth.beginning_of_day User.minimum_required_age.years.ago.beginning_of_day < response.date_of_birth.beginning_of_day
end end
def verified? def verified?

View File

@@ -36,7 +36,7 @@ class Verification::Residence
def allowed_age def allowed_age
return if errors[:date_of_birth].any? 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 end
def document_number_uniqueness def document_number_uniqueness

View File

@@ -29,7 +29,7 @@ en:
not_in_census_info: 'Citizens not in the Census can participate in the website with the following permissions:' 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. please_check_account_data: Please check that the account data above are correct.
title: User management 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 verify: Verify
email_label: Email email_label: Email
email_verifications: email_verifications:

View File

@@ -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:' 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. please_check_account_data: Compruebe que los datos anteriores son correctos para proceder a verificar la cuenta completamente.
title: Gestión de usuarios 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 verify: Verificar usuario
email_label: Email email_label: Email
email_verifications: email_verifications:

View File

@@ -59,7 +59,7 @@ en:
residence_card: Residence card residence_card: Residence card
spanish_id: DNI spanish_id: DNI
document_type_label: Document type 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_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: 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 error_verifying_census_offices: Citizen Support Office

View File

@@ -59,7 +59,7 @@ es:
residence_card: Tarjeta de residencia residence_card: Tarjeta de residencia
spanish_id: DNI spanish_id: DNI
document_type_label: Tipo de documento 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_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: 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 error_verifying_census_offices: oficina de Atención al ciudadano

View File

@@ -63,13 +63,13 @@ feature 'DocumentVerifications' do
end end
scenario 'User age is checked' do 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 visit management_document_verifications_path
fill_in 'document_verification_document_number', with: '12345678Z' fill_in 'document_verification_document_number', with: '12345678Z'
click_button 'Check' 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
end end

View File

@@ -27,7 +27,7 @@ describe Verification::Residence do
it "should validate user has allowed age" 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}"}) 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).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 end
it "should validate uniquness of document_number" do it "should validate uniquness of document_number" do

View File

@@ -18,20 +18,20 @@ describe Verification::Management::Document do
end end
end end
describe "#under_sixteen?" do describe "#under_age?" do
it "returns true when the user is younger than sixteen years old" 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(16.years.ago.year, 12, 31)) census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be true expect(Verification::Management::Document.new.under_age?(census_response)).to be true
end end
it "returns false when the user is sixteen years old" do it "returns false when the user is user's minimum required age" do
census_response = double(date_of_birth: Date.new(16.years.ago.year, 16.years.ago.month, 16.years.ago.day)) 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_sixteen?(census_response)).to be false expect(Verification::Management::Document.new.under_age?(census_response)).to be false
end end
it "returns false when the user is older than sixteen years old" do it "returns false when the user is older than user's minimum required age" do
census_response = double(date_of_birth: Date.new(33.years.ago.year, 12, 31)) census_response = double(date_of_birth: Date.new((User.minimum_required_age + 10).years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false expect(Verification::Management::Document.new.under_age?(census_response)).to be false
end end
end end
end end