Naming: Ambiguos ‘date_of_birth'

Actually we are using 'date_of_birth' as method and as attribute
accessor.
- Refactor 'date_of_birth' method to 'response_date_of_birth’
This commit is contained in:
taitus
2019-04-25 16:58:46 +02:00
committed by Javi Martín
parent dd14fd8649
commit ff5f7ad401
2 changed files with 5 additions and 5 deletions

View File

@@ -35,7 +35,7 @@ class Officing::Residence
document_number: document_number,
document_type: document_type,
geozone: geozone,
date_of_birth: date_of_birth.in_time_zone.to_datetime,
date_of_birth: response_date_of_birth.in_time_zone.to_datetime,
gender: gender,
residence_verified_at: Time.current,
verified_at: Time.current,
@@ -86,7 +86,7 @@ class Officing::Residence
end
def allowed_age?
Age.in_years(date_of_birth) >= User.minimum_required_age
Age.in_years(response_date_of_birth) >= User.minimum_required_age
end
def geozone
@@ -101,7 +101,7 @@ class Officing::Residence
@census_api_response.gender
end
def date_of_birth
def response_date_of_birth
@census_api_response.date_of_birth
end

View File

@@ -113,13 +113,13 @@ describe Officing::Residence do
describe "allowed age" do
it "is not valid if user is under allowed age" do
allow_any_instance_of(described_class).to receive(:date_of_birth).and_return(15.years.ago)
allow_any_instance_of(described_class).to receive(:response_date_of_birth).and_return(15.years.ago)
expect(residence).not_to be_valid
expect(residence.errors[:year_of_birth]).to include("You don't have the required age to participate")
end
it "is valid if user is above allowed age" do
allow_any_instance_of(described_class).to receive(:date_of_birth).and_return(16.years.ago)
allow_any_instance_of(described_class).to receive(:response_date_of_birth).and_return(16.years.ago)
expect(residence).to be_valid
expect(residence.errors[:year_of_birth]).to be_empty
end