diff --git a/app/models/log.rb b/app/models/log.rb index 9bb64a515..48343a761 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -80,7 +80,6 @@ class Log < ApplicationRecord def process_address_change! if [address_line1_input, postcode_full_input].all?(&:present?) && (address_selection.present? || select_best_address_match.present?) - address_string = "#{address_line1_input}, , , #{postcode_full_input}" service = AddressClient.new(address_string) service.call @@ -120,6 +119,10 @@ class Log < ApplicationRecord end end + def address_string + "#{address_line1_input}, , , #{postcode_full_input}" + end + def address_options return @address_options if @address_options diff --git a/spec/models/form/lettings/pages/address_matcher_spec.rb b/spec/models/form/lettings/pages/address_matcher_spec.rb index 2476971f9..284e18825 100644 --- a/spec/models/form/lettings/pages/address_matcher_spec.rb +++ b/spec/models/form/lettings/pages/address_matcher_spec.rb @@ -28,6 +28,6 @@ RSpec.describe Form::Lettings::Pages::AddressMatcher, type: :model do end it "has correct depends_on" do - expect(page.depends_on).to eq([{"is_supported_housing?"=>false, "uprn_known"=>nil}, {"is_supported_housing?"=>false, "uprn_known"=>0}, {"is_supported_housing?"=>false, "uprn_confirmed"=>0}]) + expect(page.depends_on).to eq([{ "is_supported_housing?" => false, "uprn_known" => nil }, { "is_supported_housing?" => false, "uprn_known" => 0 }, { "is_supported_housing?" => false, "uprn_confirmed" => 0 }]) end end diff --git a/spec/models/form/lettings/questions/address_selection_spec.rb b/spec/models/form/lettings/questions/address_selection_spec.rb index bb3941d8c..068272abe 100644 --- a/spec/models/form/lettings/questions/address_selection_spec.rb +++ b/spec/models/form/lettings/questions/address_selection_spec.rb @@ -7,10 +7,12 @@ RSpec.describe Form::Lettings::Questions::AddressSelection, type: :model do let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } let(:log) { create(:lettings_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } + let(:address_client_instance) { AddressClient.new(log.address_string) } before do - allow_any_instance_of(AddressClient).to receive(:call) - allow_any_instance_of(AddressClient).to receive(:result).and_return([{ + allow(AddressClient).to receive(:new).and_return(address_client_instance) + allow(address_client_instance).to receive(:call) + allow(address_client_instance).to receive(:result).and_return([{ "UPRN" => "UPRN", "UDPRN" => "UDPRN", "ADDRESS" => "full address", @@ -87,7 +89,7 @@ RSpec.describe Form::Lettings::Questions::AddressSelection, type: :model do context "when the log does not have address options" do before do - allow_any_instance_of(AddressClient).to receive(:result).and_return(nil) + allow(address_client_instance).to receive(:result).and_return(nil) end it "has the correct hidden_in_check_answers?" do