From cf157800bd9486fe5e71669e4f1008e96a052cab Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Wed, 6 Mar 2024 11:41:06 +0000 Subject: [PATCH] CLDC-3279: Ignore reasonother field in bulk upload if reason is not other --- .../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 6ba9ab69a..d237e2805 100644 --- a/app/services/bulk_upload/lettings/year2024/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2024/row_parser.rb @@ -1138,7 +1138,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 @@ -1509,4 +1509,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 73e639449..98d0fdfe6 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb @@ -2136,10 +2136,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