Fixes errors on verification/residence specs
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
class Verification::Residence
|
class Verification::Residence
|
||||||
include ActiveModel::Model
|
include ActiveModel::Model
|
||||||
include ActiveModel::Dates
|
include ActiveModel::Dates
|
||||||
|
include ActiveModel::Validations::Callbacks
|
||||||
|
|
||||||
attr_accessor :user, :document_number, :document_type, :date_of_birth, :postal_code, :terms_of_service
|
attr_accessor :user, :document_number, :document_type, :date_of_birth, :postal_code, :terms_of_service
|
||||||
|
|
||||||
|
before_validation :call_census_api
|
||||||
|
|
||||||
validates_presence_of :document_number
|
validates_presence_of :document_number
|
||||||
validates_presence_of :document_type
|
validates_presence_of :document_type
|
||||||
validates_presence_of :date_of_birth
|
validates_presence_of :date_of_birth
|
||||||
@@ -24,11 +27,10 @@ class Verification::Residence
|
|||||||
end
|
end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
@census_api_response = CensusApi.new.call(document_type, document_number)
|
|
||||||
return false unless valid?
|
return false unless valid?
|
||||||
user.update(document_number: document_number,
|
user.update(document_number: document_number,
|
||||||
document_type: document_type,
|
document_type: document_type,
|
||||||
geozone: geozone,
|
geozone: self.geozone,
|
||||||
residence_verified_at: Time.now)
|
residence_verified_at: Time.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -66,14 +68,18 @@ class Verification::Residence
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def geozone
|
||||||
|
Geozone.where(census_code: district_code).first!
|
||||||
|
end
|
||||||
|
|
||||||
def district_code
|
def district_code
|
||||||
@census_api_response.district_code
|
@census_api_response.district_code
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def geozone
|
def call_census_api
|
||||||
Geozone.find_by!(census_code: district_code)
|
@census_api_response = CensusApi.new.call(document_type, document_number)
|
||||||
end
|
end
|
||||||
|
|
||||||
def residency_valid?
|
def residency_valid?
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ require 'rails_helper'
|
|||||||
|
|
||||||
describe Verification::Residence do
|
describe Verification::Residence do
|
||||||
|
|
||||||
let(:geozone) { create(:geozone, census_code: "01") }
|
let!(:geozone) { create(:geozone, census_code: "01") }
|
||||||
let(:residence) { build(:verification_residence, document_number: "12345678Z") }
|
let(:residence) { build(:verification_residence, document_number: "12345678Z") }
|
||||||
|
|
||||||
describe "validations" do
|
describe "validations" do
|
||||||
|
|||||||
Reference in New Issue
Block a user