From daa817c574963eb638431c6cc702c272e184e4a3 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Thu, 14 Mar 2024 15:12:29 +0000 Subject: [PATCH] CLDC-3279: Ignore reasonother field in bulk upload if reason is not other (#2291) --- .../bulk_upload/lettings/year2024/row_parser.rb | 6 +++++- .../lettings/year2024/row_parser_spec.rb | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2024/row_parser.rb b/app/services/bulk_upload/lettings/year2024/row_parser.rb index e03fd4817..8b5fe8f3c 100644 --- a/app/services/bulk_upload/lettings/year2024/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2024/row_parser.rb @@ -1192,7 +1192,7 @@ private attributes["layear"] = field_96 attributes["waityear"] = field_97 attributes["reason"] = field_98 - attributes["reasonother"] = field_99 + attributes["reasonother"] = field_99 if reason_is_other? attributes["prevten"] = field_100 attributes["homeless"] = field_101 @@ -1570,4 +1570,8 @@ private def is_carehome field_124.present? ? 1 : 0 end + + def reason_is_other? + field_98 == 20 + end end diff --git a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb index cd398dabd..f99052d99 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb @@ -2223,10 +2223,20 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end describe "#reasonother" do - let(:attributes) { { bulk_upload:, field_99: "some other reason" } } + context "when reason is 'other'" do + let(:attributes) { { bulk_upload:, field_98: "20", field_99: "some other reason" } } - it "sets value to given free text string" do - expect(parser.log.reasonother).to eql("some other reason") + it "is set to given free text string" do + expect(parser.log.reasonother).to eql("some other reason") + end + end + + context "when reason is not 'other'" do + let(:attributes) { { bulk_upload:, field_98: "50", field_99: "some other reason" } } + + it "is set to nil" do + expect(parser.log.reasonother).to be_nil + end end end