From ba9cdd31a2799bfcb663602f1afce3014615d393 Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Tue, 2 Nov 2021 09:00:35 +0000 Subject: [PATCH] Code review updates --- app/validations/household_validations.rb | 9 ++++++++- docs/api/DLUHC-CORE-Data.v1.json | 4 ++-- spec/factories/case_log.rb | 2 +- spec/features/case_log_spec.rb | 2 +- spec/requests/case_log_controller_spec.rb | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/validations/household_validations.rb b/app/validations/household_validations.rb index 347b87c59..45e881a4f 100644 --- a/app/validations/household_validations.rb +++ b/app/validations/household_validations.rb @@ -63,7 +63,14 @@ module HouseholdValidations end def validate_person_1_age(record) - validate_person_age(record, 1) + return unless record.person_1_age + if !record.person_1_age.is_a?(Integer) || record.person_1_age < 16 || record.person_1_age > 120 + record.errors.add "person_1_age", "Tenant age must be an integer between 16 and 120" + end + end + + def validate_person_1_economic(record) + validate_person_age_matches_economic_status(record, 1) end private diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index fed09b9d6..e4e08d15f 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -110,7 +110,7 @@ "value": { "errors": { "person_1_age": [ - "Tenant age must be an integer between 0 and 120" + "Tenant age must be an integer between 16 and 120" ] } } @@ -220,7 +220,7 @@ "If reasonable preference is Yes, a reason must be given" ], "person_1_age": [ - "Tenant age must be an integer between 0 and 120" + "Tenant age must be an integer between 16 and 120" ] } } diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 6e5960329..bed593844 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -6,7 +6,7 @@ FactoryBot.define do tenant_code { "TH356" } property_postcode { "SW2 6HI" } previous_postcode { "P0 5ST" } - person_1_age { "12" } + person_1_age { "18" } end trait :completed do status { 2 } diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 587fc80f1..6d26628f2 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -184,7 +184,7 @@ RSpec.describe "Test Features" do it "displays text answers in inputs if they are already saved" do visit("/case_logs/#{id}/person_1_age") - expect(page).to have_field("case-log-person-1-age-field", with: "12") + expect(page).to have_field("case-log-person-1-age-field", with: "18") end it "displays checkbox answers in inputs if they are already saved" do diff --git a/spec/requests/case_log_controller_spec.rb b/spec/requests/case_log_controller_spec.rb index 50a2250ed..d3f67683b 100644 --- a/spec/requests/case_log_controller_spec.rb +++ b/spec/requests/case_log_controller_spec.rb @@ -66,7 +66,7 @@ RSpec.describe CaseLogsController, type: :request do it "validates case log parameters" do json_response = JSON.parse(response.body) expect(response).to have_http_status(:unprocessable_entity) - expect(json_response["errors"]).to match_array([["property_number_of_times_relet", ["Property number of times relet must be between 0 and 20"]], ["person_1_age", ["Tenant age must be an integer between 0 and 120"]]]) + expect(json_response["errors"]).to match_array([["property_number_of_times_relet", ["Property number of times relet must be between 0 and 20"]], ["person_1_age", ["Tenant age must be an integer between 16 and 120"]]]) end end @@ -165,7 +165,7 @@ RSpec.describe CaseLogsController, type: :request do it "returns an error message" do json_response = JSON.parse(response.body) - expect(json_response["errors"]).to eq({ "person_1_age" => ["Tenant age must be an integer between 0 and 120"] }) + expect(json_response["errors"]).to eq({ "person_1_age" => ["Tenant age must be an integer between 16 and 120"] }) end end