Browse Source

Code review updates

pull/74/head
Matthew Phelan 3 years ago
parent
commit
ba9cdd31a2
  1. 9
      app/validations/household_validations.rb
  2. 4
      docs/api/DLUHC-CORE-Data.v1.json
  3. 2
      spec/factories/case_log.rb
  4. 2
      spec/features/case_log_spec.rb
  5. 4
      spec/requests/case_log_controller_spec.rb

9
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

4
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"
]
}
}

2
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 }

2
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

4
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

Loading…
Cancel
Save