Skip to content

Commit

Permalink
Merge pull request #6472 from ministryofjustice/ap-4908-overseas-home…
Browse files Browse the repository at this point in the history
…-address-fixes

Ap 4908 overseas home address fixes
  • Loading branch information
kmahern authored Mar 21, 2024
2 parents 638a029 + 547ac86 commit 677f328
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ def update

private

def build_address
Address.new(
applicant:,
location: "home",
)
end

def non_uk_home_address
applicant.home_address || applicant.build_address(location: "home")
@non_uk_home_address ||= applicant.home_address || build_address
end

def form_params
merge_with_model(non_uk_home_address) do
params.require(:non_uk_home_address).permit(
:country, :address_line_one, :address_line_two, :city, :county
)
).merge(postcode: nil)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/forms/addresses/non_uk_home_address_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Addresses
class NonUkHomeAddressForm < BaseForm
form_for Address

attr_accessor :country, :address_line_one, :address_line_two, :city, :county
attr_accessor :country, :address_line_one, :address_line_two, :city, :county, :postcode

validates :country, :address_line_one, presence: true, unless: :draft?

Expand Down
2 changes: 0 additions & 2 deletions app/services/flow/flows/provider_start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ class ProviderStart < FlowSteps
carry_on_sub_flow: ->(application) { !application.applicant.no_fixed_residence? },
},
non_uk_home_addresses: {
# :nocov:
path: ->(application) { urls.providers_legal_aid_application_home_address_non_uk_home_address_path(application) },
# :nocov:
forward: lambda do |application|
if Setting.linked_applications?
:copy_case_invitations
Expand Down
5 changes: 3 additions & 2 deletions spec/helpers/providers_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
%w[home_addresses
home_address_lookups
home_address_selections
home_address_different_address_reaons
home_address_different_addresses]
different_address_reasons
different_addresses
non_uk_home_addresses]
end

describe "#url_for_application" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
let(:legal_aid_application) { create(:legal_aid_application, :with_applicant) }
let(:applicant) { legal_aid_application.applicant }
let(:provider) { legal_aid_application.provider }
let(:address) { applicant.home_address }
let(:address) { applicant.address }
let(:home_address) { applicant.home_address }
let(:country) { "China" }
let(:address_line_one) { "Maple Leaf Education Building" }
let(:address_line_two) { "No. 13 Baolong 1st Road" }
Expand Down Expand Up @@ -85,14 +86,14 @@
end
end

it "creates an address record" do
it "creates a home address record" do
expect { patch_request }.to change { applicant.addresses.count }.by(1)
expect(address.location).to eq("home")
expect(address.address_line_one).to eq(address_params[:non_uk_home_address][:address_line_one])
expect(address.address_line_two).to eq(address_params[:non_uk_home_address][:address_line_two])
expect(address.city).to eq(address_params[:non_uk_home_address][:city])
expect(address.county).to eq(address_params[:non_uk_home_address][:county])
expect(address.postcode).to be_nil
expect(home_address.location).to eq("home")
expect(home_address.address_line_one).to eq(address_params[:non_uk_home_address][:address_line_one])
expect(home_address.address_line_two).to eq(address_params[:non_uk_home_address][:address_line_two])
expect(home_address.city).to eq(address_params[:non_uk_home_address][:city])
expect(home_address.county).to eq(address_params[:non_uk_home_address][:county])
expect(home_address.postcode).to be_nil
end
end

Expand All @@ -105,22 +106,54 @@
end
end

context "with an already existing address" do
before { create(:address, applicant:) }
context "with an already existing correspondence address but no home address" do
before do
create(:address, applicant:, location: "correspondence")
end

it "creates a new address record" do
expect { patch_request }.to change { applicant.addresses.count }.by(1)
end

it "does not update the correspondence address" do
expect { patch_request }.not_to change(applicant, :address)
end

it "updates the current home address" do
patch_request
expect(home_address.location).to eq("home")
expect(home_address.address_line_one).to eq(address_line_one)
expect(home_address.address_line_two).to eq(address_line_two)
expect(home_address.city).to eq(city)
expect(home_address.county).to eq(county)
expect(home_address.country).to eq(country)
expect(home_address.postcode).to be_nil
end
end

context "with an already existing correspondence address and home address" do
before do
create(:address, applicant:, location: "correspondence")
create(:address, applicant:, location: "home")
end

it "does not create a new address record" do
expect { patch_request }.not_to change { applicant.addresses.count }
end

it "updates the current address" do
it "does not update the correspondence address" do
expect { patch_request }.not_to change(applicant, :address)
end

it "updates the current home address" do
patch_request
expect(address.location).to eq("home")
expect(address.address_line_one).to eq(address_line_one)
expect(address.address_line_two).to eq(address_line_two)
expect(address.city).to eq(city)
expect(address.county).to eq(county)
expect(address.country).to eq(country)
expect(address.postcode).to be_nil
expect(home_address.location).to eq("home")
expect(home_address.address_line_one).to eq(address_line_one)
expect(home_address.address_line_two).to eq(address_line_two)
expect(home_address.city).to eq(city)
expect(home_address.county).to eq(county)
expect(home_address.country).to eq(country)
expect(home_address.postcode).to be_nil
end
end

Expand Down

0 comments on commit 677f328

Please sign in to comment.