Skip to content

Commit

Permalink
AP-5220: Delete home address when applicant has no fixed address
Browse files Browse the repository at this point in the history
Delete home address when applicant has said they have no fixed address. This
is most important when they have already entered an address, so it will now
be removed.

Updated wording in spec to be clearer
  • Loading branch information
agoldstone93 committed Aug 22, 2024
1 parent 036f48e commit fbb1b84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 7 additions & 0 deletions app/controllers/providers/home_address/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ def update
@form = ::HomeAddress::StatusForm.new(form_params)
@correspondence_address = applicant.address

delete_home_address if form_params[:no_fixed_residence].eql?("true")

render :show unless save_continue_or_draft(@form)
end

private

def delete_home_address
applicant.home_address = nil
applicant.save!
end

def applicant
legal_aid_application.applicant
end
Expand Down
17 changes: 11 additions & 6 deletions spec/requests/providers/home_address/statuses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
it_behaves_like "a provider not authenticated"
end

context "when yes chosen" do
let(:params) { { applicant: { no_fixed_residence: "true" } } }
context "when applicant does have a home address" do
let(:params) { { applicant: { no_fixed_residence: "false" } } }

it "records the answer" do
expect { patch_request }.to change { applicant.reload.no_fixed_residence }.from(nil).to(true)
expect { patch_request }.to change { applicant.reload.no_fixed_residence }.from(nil).to(false)
end

it "redirects to the next page" do
Expand All @@ -55,11 +55,16 @@
end
end

context "when no chosen" do
let(:params) { { applicant: { no_fixed_residence: "false" } } }
context "when applicant does not have a home address" do
let(:params) { { applicant: { no_fixed_residence: "true" } } }

it "records the answer" do
expect { patch_request }.to change { applicant.reload.no_fixed_residence }.from(nil).to(false)
expect { patch_request }.to change { applicant.reload.no_fixed_residence }.from(nil).to(true)
end

it "deletes the home address" do
patch_request
expect(applicant.reload.home_address).to be_nil
end

it "redirects to the next page" do
Expand Down

0 comments on commit fbb1b84

Please sign in to comment.