ifage>=16&&age<=19&&relationship=="Child - includes young adult and grown-up"&&(economic_status!="Full-time student"||economic_status!="Prefer not to say")
record.errors.add"person_#{person_num}_economic_status","If age is between 16 and 19 - tenant #{person_num} must be a full time student or prefer not to say."
it"validate that persons aged under 16 must be a child (economically speaking)"do
expect{CaseLog.create!(person_2_age:15,person_2_economic_status:"Full-time - 30 hours or more")}.toraise_error(ActiveRecord::RecordInvalid)
end
it"validate that persons aged between 16 and 19 that are a child must be a full time student or economic status refused"do
expect{CaseLog.create!(person_2_age:17,person_2_relationship:"Child - includes young adult and grown-up",person_2_economic_status:"Full-time - 30 hours or more")}.toraise_error(ActiveRecord::RecordInvalid)
end
it"validate that persons aged under 16 must be a child relationship"do
expect(json_response["errors"]).tomatch_array([["property_number_of_times_relet",["Must be between 0 and 20"]],["person_1_age",["Tenant age must be between 0 and 120"]]])
expect(json_response["errors"]).tomatch_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
end
end
@ -165,7 +165,7 @@ RSpec.describe CaseLogsController, type: :request do
it"returns an error message"do
it"returns an error message"do
json_response=JSON.parse(response.body)
json_response=JSON.parse(response.body)
expect(json_response["errors"]).toeq({"person_1_age"=>["Tenant age must be between 0 and 120"]})
expect(json_response["errors"]).toeq({"person_1_age"=>["Tenant age must be an integer between 16 and 120"]})