record.errors.add:reasonable_preference_reason,"- if reasonable preference is No, no reasons should be given"
record.errors.add:reasonable_preference_reason,"If reasonable preference is No, no reasons should be given"
end
end
end
@ -45,6 +45,16 @@ class CaseLogValidator < ActiveModel::Validator
end
end
defvalidate_armed_forces_injured(record)
if(record.armed_forces=="Yes - a regular"||record.armed_forces=="Yes - a reserve")&&record.armed_forces_injured.blank?
record.errors.add:armed_forces_injured,"You must answer the armed forces injury question if the tenant has served in the armed forces"
end
if(record.armed_forces=="No"||record.armed_forces=="Prefer not to say")&&record.armed_forces_injured.present?
record.errors.add:armed_forces_injured,"You must not answer the armed forces injury question if the tenant has not served in the armed forces or prefer not to say was chosen"
end
end
defvalidate(record)
# If we've come from the form UI we only want to validate the specific fields
# that have just been submitted. If we're submitting a log via API or Bulk Upload
expect(json_response["errors"]).tomatch_array(["Tenant age must be between 0 and 120","Property number of times relet must be between 0 and 20"])
expect(json_response["errors"]).tomatch_array([["property_number_of_times_relet",["Must be between 0 and 20"]],["tenant_age",["Tenant age must be between 0 and 120"]]])
end
end
@ -157,7 +157,7 @@ RSpec.describe CaseLogsController, type: :request do
it"returns an error message"do
json_response=JSON.parse(response.body)
expect(json_response["errors"]).toeq(["Tenant age must be between 0 and 120"])
expect(json_response["errors"]).toeq({"tenant_age"=>["Tenant age must be between 0 and 120"]})