Browse Source

refactor: avoid stubbing using any_instance_of

pull/2278/head
natdeanlewissoftwire 2 years ago
parent
commit
241f51d01a
  1. 5
      app/models/log.rb
  2. 2
      spec/models/form/lettings/pages/address_matcher_spec.rb
  3. 8
      spec/models/form/lettings/questions/address_selection_spec.rb

5
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

2
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

8
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

Loading…
Cancel
Save