checks valid age

This commit is contained in:
rgarcia
2015-10-19 11:20:32 +02:00
parent 573b2425d0
commit 0a668ae39a
5 changed files with 33 additions and 6 deletions

View File

@@ -17,7 +17,21 @@ class Verification::Management::Document
end
def in_census?
CensusApi.new.call(document_type, document_number).valid?
response = CensusApi.new.call(document_type, document_number)
response.valid? && valid_age?(response)
end
def valid_age?(response)
if under_sixteen?(response)
errors.add(:age, true)
return false
else
return true
end
end
def under_sixteen?(response)
16.years.ago.year < response.date_of_birth.to_date.year
end
def verified?
@@ -28,7 +42,4 @@ class Verification::Management::Document
user.update(verified_at: Time.now) if user?
end
end
end

View File

@@ -1,5 +1,9 @@
<div class="alert-box alert radius">
<%= t("management.document_verifications.not_in_census") %>
<% if @document_verification.errors[:age].any? %>
<%= t("management.document_verifications.under_age") %>
<% else %>
<%= t("management.document_verifications.not_in_census") %>
<% end %>
</div>
<%= render 'management/user_permissions',

View File

@@ -41,6 +41,7 @@ en:
already_verified: "This user account is already verified."
in_census_has_following_permissions: "This user can participate in the website with the following permissions:"
not_in_census: "This document is not registered in Madrid."
under_age: "You must be over 16 to verify your account."
not_in_census_info: "Citizens not in the Census can participate in the website with the following permissions:"
has_no_account_html: "In order to create an account, go to %{link} and click in <b>'Register'</b> in the upper-left part of the screen."
verify: "Verify"

View File

@@ -41,6 +41,7 @@ es:
already_verified: "Esta cuenta de usuario ya está verificada."
in_census_has_following_permissions: "Este usuario puede participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:"
not_in_census: "Este documento no está registrado en el Padrón Municipal de Madrid."
under_age: "Debes ser mayor de 16 años para verificar tu cuenta."
not_in_census_info: "Las personas no empadronadas en Madrid pueden participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:"
has_no_account_html: "Para crear un usuario entre en %{link} y haga clic en la opción <b>'Registrarse'</b> en la parte superior derecha de la pantalla."
verify: "Verificar usuario"

View File

@@ -62,4 +62,14 @@ feature 'DocumentVerifications' do
expect(page).to have_content "Document number: 12345H"
end
scenario 'User age is checked' do
expect_any_instance_of(Verification::Management::Document).to receive(:under_sixteen?).and_return(true)
visit management_document_verifications_path
fill_in 'document_verification_document_number', with: '1234'
click_button 'Check'
expect(page).to have_content "You must be over 16 to verify your account."
end
end