From 0ff387ad84e83782ce9ab928ce95888f16b56cc1 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 13 Feb 2023 08:47:21 +0000 Subject: [PATCH] Remove nils before adding up location units (#1290) --- app/services/exports/lettings_log_export_service.rb | 2 +- spec/services/exports/lettings_log_export_service_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/services/exports/lettings_log_export_service.rb b/app/services/exports/lettings_log_export_service.rb index 6cc5c1f52..aed3ea98a 100644 --- a/app/services/exports/lettings_log_export_service.rb +++ b/app/services/exports/lettings_log_export_service.rb @@ -214,7 +214,7 @@ module Exports attribute_hash["reghome"] = scheme.registered_under_care_act_before_type_cast attribute_hash["schtype"] = scheme.scheme_type_before_type_cast attribute_hash["support"] = scheme.support_type_before_type_cast - attribute_hash["units_scheme"] = scheme.locations.map(&:units).sum + attribute_hash["units_scheme"] = scheme.locations.map(&:units).compact.sum end def add_location_fields!(location, attribute_hash) diff --git a/spec/services/exports/lettings_log_export_service_spec.rb b/spec/services/exports/lettings_log_export_service_spec.rb index a8d626b98..36adda071 100644 --- a/spec/services/exports/lettings_log_export_service_spec.rb +++ b/spec/services/exports/lettings_log_export_service_spec.rb @@ -258,6 +258,10 @@ RSpec.describe Exports::LettingsLogExportService do let(:lettings_log) { FactoryBot.create(:lettings_log, :completed, :export, :sh, scheme:, location:, created_by: user, owning_organisation: organisation, startdate: Time.utc(2022, 2, 2, 10, 36, 49), underoccupation_benefitcap: 4, sheltered: 1) } + before do + FactoryBot.create(:location, scheme:, startdate: Time.zone.local(2021, 4, 1), units: nil) + end + it "generates an XML export file with the expected content" do expected_content = replace_entity_ids(lettings_log, export_file.read) expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) do |_, content|