Browse Source

Memoise lettings forms in form handler (#1845)

* feat: memoise lettings forms

* feat: update tests
deduplication-demo
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
d73116f098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/models/form_handler.rb
  2. 1
      spec/models/form_spec.rb
  3. 2
      spec/models/lettings_log_spec.rb

5
app/models/form_handler.rb

@ -75,6 +75,10 @@ class FormHandler
end end
def lettings_forms def lettings_forms
@lettings_forms ||= get_lettings_forms
end
def get_lettings_forms
forms = {} forms = {}
directories.each do |directory| directories.each do |directory|
Dir.glob("#{directory}/*.json").each do |form_path| Dir.glob("#{directory}/*.json").each do |form_path|
@ -154,6 +158,7 @@ class FormHandler
def use_real_forms! def use_real_forms!
@directories = ["config/forms"] @directories = ["config/forms"]
@lettings_forms = get_lettings_forms
@forms = get_all_forms @forms = get_all_forms
end end

1
spec/models/form_spec.rb

@ -188,7 +188,6 @@ RSpec.describe Form, type: :model do
around do |example| around do |example|
FormHandler.instance.use_real_forms! FormHandler.instance.use_real_forms!
example.run example.run
end end

2
spec/models/lettings_log_spec.rb

@ -1575,6 +1575,7 @@ RSpec.describe LettingsLog do
it "clears underoccupation_benefitcap if log is no longer in 2021/22" do it "clears underoccupation_benefitcap if log is no longer in 2021/22" do
expect { lettings_log.update!(renewal: 1) }.to change(lettings_log, :underoccupation_benefitcap).to 2 expect { lettings_log.update!(renewal: 1) }.to change(lettings_log, :underoccupation_benefitcap).to 2
Timecop.return Timecop.return
Singleton.__init__(FormHandler)
expect { lettings_log.update!(startdate: Time.zone.local(2023, 1, 1)) }.to change(lettings_log, :underoccupation_benefitcap).from(2).to nil expect { lettings_log.update!(startdate: Time.zone.local(2023, 1, 1)) }.to change(lettings_log, :underoccupation_benefitcap).from(2).to nil
end end
@ -2040,6 +2041,7 @@ RSpec.describe LettingsLog do
before do before do
Timecop.freeze(Time.zone.local(2022, 4, 2)) Timecop.freeze(Time.zone.local(2022, 4, 2))
Singleton.__init__(FormHandler)
lettings_log.update!(startdate: Time.zone.local(2022, 4, 2), scheme:) lettings_log.update!(startdate: Time.zone.local(2022, 4, 2), scheme:)
Timecop.unfreeze Timecop.unfreeze
end end

Loading…
Cancel
Save