From 3d2699e557525e960fadf11e4ccae00ef95dee81 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Wed, 27 Oct 2021 09:33:58 +0100 Subject: [PATCH 1/3] added simple validation for outstanding rent --- app/models/case_log.rb | 9 +++++++++ spec/models/case_log_spec.rb | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index aad4d23b0..ef4655a7a 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -55,6 +55,15 @@ class CaseLogValidator < ActiveModel::Validator end end + def validate_outstanding_rent_amount(record) + if record.outstanding_rent_or_charges == "Yes" && record.outstanding_amount.blank? + record.errors.add :outstanding_amount, "You must answer the oustanding amout question if you have outstanding rent or charges." + end + if record.outstanding_rent_or_charges == "No" && !record.outstanding_amount.blank? + record.errors.add :outstanding_amount, "You must not answer the oustanding amout question if you don't have outstanding rent or charges." + end + end + def validate(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 diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 265296e40..aaa7f8c84 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -96,6 +96,22 @@ RSpec.describe Form, type: :model do }.to raise_error(ActiveRecord::RecordInvalid) end end + + context "outstanding rent or charges validation" do + it "must be anwered if answered yes to outstanding rent or charges" do + expect { + CaseLog.create!(outstanding_rent_or_charges: "Yes", + outstanding_amount: nil) + }.to raise_error(ActiveRecord::RecordInvalid) + end + + it "must be not be anwered if answered no to outstanding rent or charges" do + expect { + CaseLog.create!(outstanding_rent_or_charges: "No", + outstanding_amount: 99) + }.to raise_error(ActiveRecord::RecordInvalid) + end + end end describe "status" do From d4497883aecb2690cfac8445121336e227ab09b7 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Wed, 27 Oct 2021 11:25:48 +0100 Subject: [PATCH 2/3] rubocop --- app/models/case_log.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index ef4655a7a..b7e7e1c0f 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -59,7 +59,7 @@ class CaseLogValidator < ActiveModel::Validator if record.outstanding_rent_or_charges == "Yes" && record.outstanding_amount.blank? record.errors.add :outstanding_amount, "You must answer the oustanding amout question if you have outstanding rent or charges." end - if record.outstanding_rent_or_charges == "No" && !record.outstanding_amount.blank? + if record.outstanding_rent_or_charges == "No" && record.outstanding_amount.present? record.errors.add :outstanding_amount, "You must not answer the oustanding amout question if you don't have outstanding rent or charges." end end From 512e3a5a82e949c185db336336df970f8cccef87 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Wed, 27 Oct 2021 14:21:05 +0100 Subject: [PATCH 3/3] added required armed forces fields to example --- docs/api/DLUHC-CORE-Data.v1.json | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index 64d5ca517..35a028ace 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -1207,6 +1207,17 @@ ] } }, - "securitySchemes": {} + "securitySchemes": { + "API Key - 1": { + "name": "API Key", + "type": "apiKey", + "in": "query" + }, + "API Key - 2": { + "name": "API Key", + "type": "apiKey", + "in": "query" + } + } } -} +} \ No newline at end of file