includes all date in document age verification
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
class Verification::Management::Document
|
class Verification::Management::Document
|
||||||
include ActiveModel::Model
|
include ActiveModel::Model
|
||||||
|
include ActiveModel::Dates
|
||||||
|
|
||||||
attr_accessor :document_type
|
attr_accessor :document_type
|
||||||
attr_accessor :document_number
|
attr_accessor :document_number
|
||||||
@@ -31,7 +32,7 @@ class Verification::Management::Document
|
|||||||
end
|
end
|
||||||
|
|
||||||
def under_sixteen?(response)
|
def under_sixteen?(response)
|
||||||
16.years.ago.year < response.date_of_birth.to_date.year
|
16.years.ago < string_to_date(response.date_of_birth)
|
||||||
end
|
end
|
||||||
|
|
||||||
def verified?
|
def verified?
|
||||||
|
|||||||
37
spec/models/verification/management/document_spec.rb
Normal file
37
spec/models/verification/management/document_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Verification::Management::Document do
|
||||||
|
describe "#valid_age?" do
|
||||||
|
it "returns false when the user is younger than sixteen years old" do
|
||||||
|
census_response = double(date_of_birth: "31-12-#{16.years.ago.year}")
|
||||||
|
expect(Verification::Management::Document.new.valid_age?(census_response)).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns true when the user is sixteen years old" do
|
||||||
|
census_response = double(date_of_birth: 16.years.ago.strftime("%d-%m-%Y"))
|
||||||
|
expect(Verification::Management::Document.new.valid_age?(census_response)).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns true when the user is older than sixteen years old" do
|
||||||
|
census_response = double(date_of_birth: "31-12-#{33.years.ago.year}")
|
||||||
|
expect(Verification::Management::Document.new.valid_age?(census_response)).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#under_sixteen?" do
|
||||||
|
it "returns true when the user is younger than sixteen years old" do
|
||||||
|
census_response = double(date_of_birth: "31-12-#{16.years.ago.year}")
|
||||||
|
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false when the user is sixteen years old" do
|
||||||
|
census_response = double(date_of_birth: 16.years.ago.strftime("%d-%m-%Y"))
|
||||||
|
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false when the user is older than sixteen years old" do
|
||||||
|
census_response = double(date_of_birth: "31-12-#{33.years.ago.year}")
|
||||||
|
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user