Browse Source

CLDC-2699 Update values updated at when updating reason field (#1909)

* Update values updated at

* Update tests
pull/1911/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
077390bb5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/services/imports/lettings_logs_field_import_service.rb
  2. 10
      spec/services/imports/lettings_logs_field_import_service_spec.rb

2
app/services/imports/lettings_logs_field_import_service.rb

@ -194,7 +194,7 @@ module Imports
if reason == 20 && reasonother.blank? if reason == 20 && reasonother.blank?
@logger.info("lettings log #{record.id}'s reason is other but other reason is not provided, skipping update") @logger.info("lettings log #{record.id}'s reason is other but other reason is not provided, skipping update")
else else
record.update!(reason:, reasonother:) record.update!(reason:, reasonother:, values_updated_at: Time.zone.now)
@logger.info("lettings log #{record.id}'s reason value has been set to #{reason}") @logger.info("lettings log #{record.id}'s reason value has been set to #{reason}")
@logger.info("lettings log #{record.id}'s reasonother value has been set to #{reasonother}") if record.reasonother.present? @logger.info("lettings log #{record.id}'s reasonother value has been set to #{reasonother}") if record.reasonother.present?
end end

10
spec/services/imports/lettings_logs_field_import_service_spec.rb

@ -481,7 +481,7 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
before do before do
Imports::LettingsLogsImportService.new(storage_service, logger).create_logs(fixture_directory) Imports::LettingsLogsImportService.new(storage_service, logger).create_logs(fixture_directory)
lettings_log_file.rewind lettings_log_file.rewind
lettings_log.update!(reason: nil) lettings_log.update!(reason: nil, values_updated_at: nil)
lettings_log_xml.at_xpath("//xmlns:Q9a").content = "47" lettings_log_xml.at_xpath("//xmlns:Q9a").content = "47"
end end
@ -489,6 +489,7 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
expect(logger).to receive(:info).with(/lettings log \d+'s reason value has been set to 47/) expect(logger).to receive(:info).with(/lettings log \d+'s reason value has been set to 47/)
expect { import_service.send(:update_reason, lettings_log_xml) } expect { import_service.send(:update_reason, lettings_log_xml) }
.to(change { lettings_log.reload.reason }.from(nil).to(47)) .to(change { lettings_log.reload.reason }.from(nil).to(47))
expect(lettings_log.values_updated_at).not_to be_nil
end end
end end
@ -498,7 +499,7 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
before do before do
Imports::LettingsLogsImportService.new(storage_service, logger).create_logs(fixture_directory) Imports::LettingsLogsImportService.new(storage_service, logger).create_logs(fixture_directory)
lettings_log_file.rewind lettings_log_file.rewind
lettings_log.update!(reason: 18) lettings_log.update!(reason: 18, values_updated_at: nil)
lettings_log_xml.at_xpath("//xmlns:Q9a").content = "47" lettings_log_xml.at_xpath("//xmlns:Q9a").content = "47"
end end
@ -506,6 +507,7 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
expect(logger).to receive(:info).with(/lettings log \d+ has a value for reason, skipping update/) expect(logger).to receive(:info).with(/lettings log \d+ has a value for reason, skipping update/)
expect { import_service.send(:update_reason, lettings_log_xml) } expect { import_service.send(:update_reason, lettings_log_xml) }
.not_to(change { lettings_log.reload.reason }) .not_to(change { lettings_log.reload.reason })
expect(lettings_log.values_updated_at).to be_nil
end end
end end
@ -515,7 +517,7 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
before do before do
Imports::LettingsLogsImportService.new(storage_service, logger).create_logs(fixture_directory) Imports::LettingsLogsImportService.new(storage_service, logger).create_logs(fixture_directory)
lettings_log_file.rewind lettings_log_file.rewind
lettings_log.update!(reason: nil) lettings_log.update!(reason: nil, values_updated_at: nil)
lettings_log_xml.at_xpath("//xmlns:Q9a").content = "20" lettings_log_xml.at_xpath("//xmlns:Q9a").content = "20"
end end
@ -529,6 +531,7 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
expect(logger).to receive(:info).with(/lettings log \d+'s reasonother value has been set to other/) expect(logger).to receive(:info).with(/lettings log \d+'s reasonother value has been set to other/)
expect { import_service.send(:update_reason, lettings_log_xml) } expect { import_service.send(:update_reason, lettings_log_xml) }
.to(change { lettings_log.reload.reason }.from(nil).to(20)) .to(change { lettings_log.reload.reason }.from(nil).to(20))
expect(lettings_log.values_updated_at).not_to be_nil
end end
end end
@ -537,6 +540,7 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
expect(logger).to receive(:info).with(/lettings log \d+'s reason is other but other reason is not provided, skipping update/) expect(logger).to receive(:info).with(/lettings log \d+'s reason is other but other reason is not provided, skipping update/)
expect { import_service.send(:update_reason, lettings_log_xml) } expect { import_service.send(:update_reason, lettings_log_xml) }
.not_to(change { lettings_log.reload.reason }) .not_to(change { lettings_log.reload.reason })
expect(lettings_log.values_updated_at).to be_nil
end end
end end
end end

Loading…
Cancel
Save