Browse Source

CLDC-3938 set ppostcode on postcode change to fix bu bug (#2994)

* set renewal ppostcode on postcode change

* update test

* don't validate ppostcode format if nil

* reset ppcodenk if ppcode errors

---------

Co-authored-by: Carolyn <carolyn.barker@softwire.com>
pull/3032/head v0.5.7
carolynbarker 2 weeks ago committed by GitHub
parent
commit
7058c9838a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      app/models/lettings_log.rb
  2. 2
      app/models/validations/local_authority_validations.rb
  3. 10
      spec/models/lettings_log_derived_fields_spec.rb

9
app/models/lettings_log.rb

@ -649,6 +649,7 @@ class LettingsLog < Log
super
self.postcode_known = nil if errors.attribute_names.include? :postcode_full
self.ppcodenk = nil if errors.attribute_names.include? :ppostcode_full
if errors.of_kind?(:earnings, :under_hard_min)
self.incfreq = nil
@ -714,9 +715,17 @@ class LettingsLog < Log
def process_postcode_changes!
self.postcode_full = upcase_and_remove_whitespace(postcode_full)
if is_renewal?
self.ppostcode_full = upcase_and_remove_whitespace(postcode_full)
end
return if postcode_full.blank?
self.postcode_known = 1
if is_renewal?
self.ppcodenk = 0
end
inferred_la = get_inferred_la(postcode_full)
self.is_la_inferred = inferred_la.present?
self.la = inferred_la if inferred_la.present?

2
app/models/validations/local_authority_validations.rb

@ -1,6 +1,8 @@
module Validations::LocalAuthorityValidations
def validate_previous_accommodation_postcode(record)
postcode = record.ppostcode_full
return unless postcode
if record.previous_postcode_known? && (postcode.blank? || !postcode.match(POSTCODE_REGEXP))
error_message = I18n.t("validations.postcode")
record.errors.add :ppostcode_full, :wrong_format, message: error_message

10
spec/models/lettings_log_derived_fields_spec.rb

@ -1016,11 +1016,13 @@ RSpec.describe LettingsLog, type: :model do
postcode = "SW1A 1AA"
log.assign_attributes(postcode_known: 1, postcode_full: postcode, renewal: 1)
expect { log.send :process_postcode_changes! }.to change(log, :la).to(expected_la)
expect { log.set_derived_fields! }
.to change(log, :ppostcode_full).to(postcode)
expect { log.send :process_postcode_changes! }
.to change(log, :la).to(expected_la)
.and change(log, :ppostcode_full).to(postcode)
.and change(log, :ppcodenk).to(0)
.and change(log, :prevloc).to(expected_la)
expect { log.set_derived_fields! }
.to change(log, :prevloc).to(expected_la)
end
it "clears values for previous location and related fields when log is a renewal and current values are cleared" do

Loading…
Cancel
Save