From 9a8945ea9a8667822ae4853287e3094617acdd15 Mon Sep 17 00:00:00 2001 From: MadeTech Dushan Date: Wed, 20 Oct 2021 10:10:22 +0100 Subject: [PATCH] dynamically not required attributes for case logs --- app/models/case_log.rb | 10 +++++++++- spec/fixtures/complete_case_log.json | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 1f4219d57..9a84c633e 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -97,6 +97,14 @@ private end def mandatory_fields - attributes.except(*AUTOGENERATED_FIELDS) + required = attributes.except(*AUTOGENERATED_FIELDS) + + dynamically_not_required = [] + + if reason_for_leaving_last_settled_home != "Other" + dynamically_not_required << "other_reason_for_leaving_last_settled_home" + end + + required.delete_if { |key, _value| dynamically_not_required.include?(key) } end end diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 11f073714..da2e0da20 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -89,7 +89,7 @@ "chr_letting": false, "cap_letting": false, "outstanding_rent_or_charges": 25, - "other_reason_for_leaving_last_settled_home": "Other reason", + "other_reason_for_leaving_last_settled_home": null, "accessibility_requirements_fully_wheelchair_accessible_housing": true, "accessibility_requirements_wheelchair_access_to_essential_rooms": false, "accessibility_requirements_level_access_housing": false,