diff --git a/app/services/exports/lettings_log_export_service.rb b/app/services/exports/lettings_log_export_service.rb
index 16ce5c187..8fafe28e9 100644
--- a/app/services/exports/lettings_log_export_service.rb
+++ b/app/services/exports/lettings_log_export_service.rb
@@ -90,11 +90,11 @@ module Exports
retrieve_lettings_logs(start_time, recent_export, full_update).filter_by_year(collection)
.where("created_at > ?", last_processed_marker)
.order(:created_at)
- .limit(MAX_XML_RECORDS)
+ .limit(MAX_XML_RECORDS).to_a
else
retrieve_lettings_logs(start_time, recent_export, full_update).filter_by_year(collection)
.order(:created_at)
- .limit(MAX_XML_RECORDS)
+ .limit(MAX_XML_RECORDS).to_a
end
break if lettings_logs_slice.empty?
diff --git a/spec/services/exports/lettings_log_export_service_spec.rb b/spec/services/exports/lettings_log_export_service_spec.rb
index 5402c19db..3913547e8 100644
--- a/spec/services/exports/lettings_log_export_service_spec.rb
+++ b/spec/services/exports/lettings_log_export_service_spec.rb
@@ -292,6 +292,44 @@ RSpec.describe Exports::LettingsLogExportService do
end
end
+ context "and underlying data changes between getting the logs and writting the manifest" do
+ before do
+ FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 2, 1))
+ FactoryBot.create(:lettings_log, startdate: Time.zone.local(2022, 4, 1))
+ end
+
+ def remove_logs(logs)
+ logs.each(&:destroy)
+ file = Tempfile.new
+ doc = Nokogiri::XML("")
+ doc.write_xml_to(file, encoding: "UTF-8")
+ file.rewind
+ file
+ end
+
+ def create_fake_maifest
+ file = Tempfile.new
+ doc = Nokogiri::XML("")
+ doc.write_xml_to(file, encoding: "UTF-8")
+ file.rewind
+ file
+ end
+
+ it "maintains the same record number" do
+ # rubocop:disable RSpec/SubjectStub
+ allow(export_service).to receive(:build_export_xml) do |logs|
+ remove_logs(logs)
+ end
+ allow(export_service).to receive(:build_manifest_xml) do
+ create_fake_maifest
+ end
+
+ expect(export_service).to receive(:build_manifest_xml).with(1)
+ # rubocop:enable RSpec/SubjectStub
+ export_service.export_xml_lettings_logs
+ end
+ end
+
context "when this is a second export (partial)" do
before do
start_time = Time.zone.local(2022, 6, 1)