Moves Age calculation to a module instead of monkeypatching Date
This commit is contained in:
@@ -68,7 +68,7 @@ class Officing::Residence
|
||||
end
|
||||
|
||||
def allowed_age?
|
||||
date_of_birth.age_in_years <= User.minimum_required_age
|
||||
Age.in_years(date_of_birth) <= User.minimum_required_age
|
||||
end
|
||||
|
||||
def geozone
|
||||
|
||||
@@ -247,7 +247,7 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def age
|
||||
date_of_birth.try(:age_in_years)
|
||||
Age.in_years(date_of_birth)
|
||||
end
|
||||
|
||||
def save_requiring_finish_signup
|
||||
|
||||
@@ -32,7 +32,7 @@ class Verification::Management::Document
|
||||
end
|
||||
|
||||
def under_age?(response)
|
||||
response.date_of_birth && User.minimum_required_age < response.date_of_birth.age_in_years
|
||||
response.date_of_birth && User.minimum_required_age < Age.in_years(response.date_of_birth)
|
||||
end
|
||||
|
||||
def verified?
|
||||
|
||||
@@ -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.age_in_years <= User.minimum_required_age
|
||||
errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless Age.in_years(self.date_of_birth) <= User.minimum_required_age
|
||||
end
|
||||
|
||||
def document_number_uniqueness
|
||||
|
||||
Reference in New Issue
Block a user