From 4d14d4bbcf956ba086fdb864f195cf177058f1ef Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Tue, 26 Nov 2024 11:36:55 +0000 Subject: [PATCH] CLDC-3768: Call process_postcode_changes when setting postcode_full from postcode_full_input (#2803) --- app/models/log.rb | 1 + spec/models/lettings_log_spec.rb | 12 ++++++++++++ spec/models/sales_log_spec.rb | 12 ++++++++++++ 3 files changed, 25 insertions(+) diff --git a/app/models/log.rb b/app/models/log.rb index aed375117..dd4301550 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -111,6 +111,7 @@ class Log < ApplicationRecord self.town_or_city = nil self.county = nil self.postcode_full = postcode_full_input + process_postcode_changes! else self.uprn = uprn_selection self.uprn_confirmed = 1 diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 5702e65c8..11e663469 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -2021,5 +2021,17 @@ RSpec.describe LettingsLog do end end end + + describe "#process_address_change!" do + context "when uprn_selection is uprn_not_listed" do + let(:log) { build(:lettings_log, uprn_selection: "uprn_not_listed", address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } + + it "sets log address fields, including postcode known" do + expect { log.process_address_change! }.to change(log, :address_line1).from(nil).to("Address line 1") + .and change(log, :postcode_full).from(nil).to("AA1 1AA") + .and change(log, :postcode_known).from(nil).to(1) + end + end + end end # rubocop:enable RSpec/MessageChain diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index f3dea90f9..9fe5a02a9 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -995,5 +995,17 @@ RSpec.describe SalesLog, type: :model do expect(sales_log.reload.is_la_inferred).to eq(false) end end + + describe "#process_address_change!" do + context "when uprn_selection is uprn_not_listed" do + let(:log) { build(:sales_log, uprn_selection: "uprn_not_listed", address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } + + it "sets log address fields, including postcode known" do + expect { log.process_address_change! }.to change(log, :address_line1).from(nil).to("Address line 1") + .and change(log, :postcode_full).from(nil).to("AA1 1AA") + .and change(log, :pcodenk).from(nil).to(0) + end + end + end end # rubocop:enable RSpec/MessageChain