uses Date#age_in_years when calculating ages

This commit is contained in:
kikito
2017-02-03 12:56:40 +01:00
parent 3535cfc0d6
commit 95f80651b1
4 changed files with 4 additions and 11 deletions

View File

@@ -68,7 +68,7 @@ class Officing::Residence
end end
def allowed_age? def allowed_age?
date_of_birth <= User.minimum_required_age.years.ago date_of_birth.age_in_years <= User.minimum_required_age
end end
def geozone def geozone

View File

@@ -247,14 +247,7 @@ class User < ActiveRecord::Base
end end
def age def age
if date_of_birth.blank? date_of_birth.try(:age_in_years)
nil
else
now = Time.now.utc.to_date
now.year - date_of_birth.year - (
(now.month > date_of_birth.month || (now.month == date_of_birth.month && now.day >= date_of_birth.day)
) ? 0 : 1)
end
end end
def save_requiring_finish_signup def save_requiring_finish_signup

View File

@@ -32,7 +32,7 @@ class Verification::Management::Document
end end
def under_age?(response) def under_age?(response)
User.minimum_required_age.years.ago.beginning_of_day < response.date_of_birth.beginning_of_day response.date_of_birth && User.minimum_required_age < response.date_of_birth.age_in_years
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 <= User.minimum_required_age.years.ago errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless self.date_of_birth.age_in_years <= User.minimum_required_age
end end
def document_number_uniqueness def document_number_uniqueness