Merge pull request #371 from AyuntamientoMadrid/residence_verification_tries
increases residence verification tries only after a Census call
This commit is contained in:
@@ -12,7 +12,6 @@ class Verification::ResidenceController < ApplicationController
|
||||
if @residence.save
|
||||
redirect_to verified_user_path, notice: t('verification.residence.create.flash.success')
|
||||
else
|
||||
current_user.update(residence_verification_tries: current_user.residence_verification_tries += 1)
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,12 +34,14 @@ class Verification::Residence
|
||||
|
||||
def residence_in_madrid
|
||||
return if errors.any?
|
||||
|
||||
self.date_of_birth = date_to_string(date_of_birth)
|
||||
|
||||
residency = CensusApi.new(self)
|
||||
errors.add(:residence_in_madrid, false) unless residency.valid?
|
||||
|
||||
unless residency.valid?
|
||||
errors.add(:residence_in_madrid, false)
|
||||
user.update(residence_verification_tries: user.residence_verification_tries += 1)
|
||||
end
|
||||
self.date_of_birth = string_to_date(date_of_birth)
|
||||
end
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ FactoryGirl.define do
|
||||
end
|
||||
|
||||
factory :verification_residence, class: Verification::Residence do
|
||||
user
|
||||
document_number '12345678Z'
|
||||
document_type 1
|
||||
date_of_birth Date.new(1980, 12, 31)
|
||||
|
||||
@@ -54,4 +54,19 @@ describe Verification::Residence do
|
||||
|
||||
end
|
||||
|
||||
describe "tries" do
|
||||
it "should increase tries after a call to the Census" do
|
||||
residence.postal_code = "12345"
|
||||
|
||||
expect { residence.valid? }.to change{
|
||||
residence.user.residence_verification_tries }.from(0).to(1)
|
||||
end
|
||||
|
||||
it "should not increase tries after a validation error" do
|
||||
residence.postal_code = ""
|
||||
expect { residence.valid? }.to_not change{
|
||||
residence.user.residence_verification_tries }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user