From 9545122114df95882ea311c45d1be0ad1a0b741c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Meny?= Date: Thu, 17 Feb 2022 10:22:47 +0000 Subject: [PATCH] Replaces enum text values in export by related numbers (#310) --- app/models/case_log.rb | 1 + .../exports/case_log_export_service.rb | 3 +- spec/fixtures/exports/case_logs.xml | 324 +++++------------- .../exports/case_log_export_service_spec.rb | 13 +- 4 files changed, 90 insertions(+), 251 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 307463a57..4c2ae50d7 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -55,6 +55,7 @@ class CaseLog < ApplicationRecord enum relat6: RELAT, _suffix: true enum relat7: RELAT, _suffix: true enum relat8: RELAT, _suffix: true + enum sex1: GENDER, _suffix: true enum sex2: GENDER, _suffix: true enum sex3: GENDER, _suffix: true enum sex4: GENDER, _suffix: true diff --git a/app/services/exports/case_log_export_service.rb b/app/services/exports/case_log_export_service.rb index 27d790ceb..72043f6ef 100644 --- a/app/services/exports/case_log_export_service.rb +++ b/app/services/exports/case_log_export_service.rb @@ -49,7 +49,8 @@ module Exports case_logs.each do |case_log| form = doc.create_element("form") doc.at("forms") << form - case_log.attributes.each do |key, value| + case_log.attributes.each do |key, _| + value = case_log.read_attribute_before_type_cast(key) form << doc.create_element(key, value) end end diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml index 63d5f3822..ac2c9a2d5 100644 --- a/spec/fixtures/exports/case_logs.xml +++ b/spec/fixtures/exports/case_logs.xml @@ -1,22 +1,22 @@
- {id_1} - completed - 2022-02-08 16:52:15 +0000 - 2022-02-08 16:52:15 +0000 + {id} + 2 + 2022-02-08 16:52:15 UTC + 2022-02-08 16:52:15 UTC BZ737 35 - Female - White: Irish - Estonia - Private sector tenancy - Part-time - Less than 30 hours + F + 2 + 4 + 3 + 2 2 - Partner + P 32 - Male - Not seeking work + M + 6 @@ -41,57 +41,57 @@ - Other homeless - not found statutorily homeless but considered homeless by landlord - No - No - they left up to 5 years ago - No - Yes - Yes + 7 + 2 + 4 + 2 + 1 + 1 BZ757 - No + 2 5 - Secure (including flexible) - This landlord + 1 + 1 SE2 6RT - Tenant abandoned property - House + 6 + 7 3 2 - Yes + 1 68 - Weekly - Some - Every 2 weeks - 1 year but under 2 years - Less than 1 year + 1 + 2 + 2 + 7 + 2 NW1 5TY - Yes - Yes - Yes - No + 1 + 1 + 1 + 0 - Yes - No - No - No - No - No - No - No - Yes - No - No - No - No - No - No - No - No - Yes - No - No - No - No + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 Test @@ -101,38 +101,38 @@ 1 2 798794 - Permanently decanted from another property owned by this landlord + 1 123 - Yes - Barnet - Ashford - Housing benefit - Yes + 1 + E09000003 + E07000105 + 1 + 1 NW1 5TY SE2 6RT - No - 2022-02-08 16:52:15 +0000 + 0 + 2022-02-08 16:52:15 UTC 8 2 2022 1 - No + 0 - 2022-02-08 16:52:15 +0000 - A current or former regular in the UK Armed Forces (excluding National Service) + 2022-02-08 16:52:15 UTC + 1 - Affordable rent basis - Purpose built - 2019-11-03 00:00:00 +0000 - {owning_org_id_1} - {managing_org_id_1} + 2 + 1 + 2019-11-03 00:00:00 UTC + {owning_org_id} + {managing_org_id} - General needs - Affordable Rent General needs LA - Yes - Yes + 1 + 7 + 1 + 1 false 8 2 @@ -140,12 +140,12 @@ 0 0 2 - Yes + 0 Yes - No - No - No - Yes + 0 + 0 + 3 + 1 200.0 50.0 @@ -154,168 +154,8 @@ 325.0 12.0 7.0 - Yes - Yes - - false - - -
- {id_2} - completed - 2022-02-08 16:52:15 +0000 - 2022-02-08 16:52:15 +0000 - BZ737 - 35 - Female - White: Irish - Estonia - Private sector tenancy - Part-time - Less than 30 hours - 2 - Partner - 32 - Male - Not seeking work - - - - - - - - - - - - - - - - - - - - - - - - - Other homeless - not found statutorily homeless but considered homeless by landlord - No - No - they left up to 5 years ago - No - Yes - Yes - BZ757 - No - 5 - Secure (including flexible) - This landlord - SE2 6RT - Tenant abandoned property - House - 3 - 2 - Yes - 68 - Weekly - Some - Every 2 weeks - 1 year but under 2 years - Less than 1 year - NW1 5TY - Yes - Yes - Yes - No - - Yes - No - No - No - No - No - No - No - Yes - No - No - No - No - No - No - No - No - Yes - No - No - No - No - - - Test - Test - - 1 - 1 - 2 - 798794 - Permanently decanted from another property owned by this landlord - 123 - Yes - Barnet - Ashford - Housing benefit - Yes - NW1 - 5TY - SE2 - 6RT - No - 2022-02-08 16:52:15 +0000 - 8 - 2 - 2022 - 1 - No - - 2022-02-08 16:52:15 +0000 - A current or former regular in the UK Armed Forces (excluding National Service) - - Affordable rent basis - Purpose built - 2019-11-03 00:00:00 +0000 - {owning_org_id_2} - {managing_org_id_2} - - General needs - Affordable Rent General needs LA - Yes - Yes - false - 8 - 2 - 2022 - 0 - 0 - 2 - Yes - Yes - No - No - No - Yes - - 200.0 - 50.0 - 40.0 - 35.0 - 325.0 - 12.0 - 7.0 - Yes - Yes + 1 + 1 false diff --git a/spec/services/exports/case_log_export_service_spec.rb b/spec/services/exports/case_log_export_service_spec.rb index 428912c48..c250f4600 100644 --- a/spec/services/exports/case_log_export_service_spec.rb +++ b/spec/services/exports/case_log_export_service_spec.rb @@ -5,15 +5,12 @@ RSpec.describe Exports::CaseLogExportService do let(:export_filepath) { "spec/fixtures/exports/case_logs.xml" } let(:export_file) { File.open(export_filepath, "r:UTF-8") } let(:expected_filename) { "core_2022_02_08/dat_core_2022_02_08_0001.xml" } - let(:case_logs) { FactoryBot.create_list(:case_log, 2, :completed) } + let(:case_log) { FactoryBot.create(:case_log, :completed) } def replace_entity_ids(export_template) - export_template.sub!(/\{id_1\}/, case_logs[0]["id"].to_s) - export_template.sub!(/\{id_2\}/, case_logs[1]["id"].to_s) - export_template.sub!(/\{owning_org_id_1\}/, case_logs[0]["owning_organisation_id"].to_s) - export_template.sub!(/\{owning_org_id_2\}/, case_logs[1]["owning_organisation_id"].to_s) - export_template.sub!(/\{managing_org_id_1\}/, case_logs[0]["managing_organisation_id"].to_s) - export_template.sub!(/\{managing_org_id_2\}/, case_logs[1]["managing_organisation_id"].to_s) + export_template.sub!(/\{id\}/, case_log["id"].to_s) + export_template.sub!(/\{owning_org_id\}/, case_log["owning_organisation_id"].to_s) + export_template.sub!(/\{managing_org_id\}/, case_log["managing_organisation_id"].to_s) end context "when exporting case logs" do @@ -21,7 +18,7 @@ RSpec.describe Exports::CaseLogExportService do before do Timecop.freeze(Time.new(2022, 2, 8, 16, 52, 15, "+00:00")) - case_logs + case_log end it "generate an XML export file with the expected filename" do