diff --git a/app/models/officing/residence.rb b/app/models/officing/residence.rb index cf69e6aba..8036c8401 100644 --- a/app/models/officing/residence.rb +++ b/app/models/officing/residence.rb @@ -68,7 +68,7 @@ class Officing::Residence end def allowed_age? - date_of_birth <= User.minimum_required_age.years.ago + date_of_birth.age_in_years <= User.minimum_required_age end def geozone diff --git a/app/models/user.rb b/app/models/user.rb index 7c72ab4b3..f092a6a7a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -247,14 +247,7 @@ class User < ActiveRecord::Base end def age - if date_of_birth.blank? - 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 + date_of_birth.try(:age_in_years) end def save_requiring_finish_signup diff --git a/app/models/verification/management/document.rb b/app/models/verification/management/document.rb index 4264154d3..f39bf4b90 100644 --- a/app/models/verification/management/document.rb +++ b/app/models/verification/management/document.rb @@ -32,7 +32,7 @@ class Verification::Management::Document end 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 def verified? diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index eda562671..040460527 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 <= 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 def document_number_uniqueness