From 4ff4a48368453da2456a0660b018ae67f302d1d2 Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Thu, 26 Mar 2026 15:34:39 +0000 Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"CLDC-4340:=20Account=20for?= =?UTF-8?q?=20nil=20location=20name=20on=20location=20select=20(=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 0a10512dc664f6a091beb4432303b868f20335d0. --- .../form/lettings/questions/location_id.rb | 7 ++--- .../lettings/questions/location_id_spec.rb | 26 +++++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/app/models/form/lettings/questions/location_id.rb b/app/models/form/lettings/questions/location_id.rb index 80e34aac0..2964298ed 100644 --- a/app/models/form/lettings/questions/location_id.rb +++ b/app/models/form/lettings/questions/location_id.rb @@ -30,11 +30,8 @@ class Form::Lettings::Questions::LocationId < ::Form::Question scheme_location_ids = lettings_log.scheme.locations.visible.confirmed.pluck(:id) answer_options.select { |k, _v| scheme_location_ids.include?(k.to_i) } - .sort_by { |_, v| - name = v["hint"].match(/[a-zA-Z].*/).to_s - number = v["hint"].match(/\d+/).to_s.to_i - [name, number] - }.to_h + .sort_by { |_, v| v["value"] } + .to_h end def hidden_in_check_answers?(lettings_log, _current_user = nil) diff --git a/spec/models/form/lettings/questions/location_id_spec.rb b/spec/models/form/lettings/questions/location_id_spec.rb index 2ea72c705..755c1f1a6 100644 --- a/spec/models/form/lettings/questions/location_id_spec.rb +++ b/spec/models/form/lettings/questions/location_id_spec.rb @@ -142,27 +142,27 @@ RSpec.describe Form::Lettings::Questions::LocationId, type: :model do context "and some locations start with numbers" do before do - FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 5), name: "2 Abe Road") - FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 6), name: "1 Abe Road") - FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 7), name: "1 Lake Lane") - FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 8), name: "3 Abe Road") - FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 9), name: "2 Lake Lane") - FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 10), name: "Smith Avenue") - FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 11), name: "Abacus Road") - FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 12), name: "Hawthorne Road") + FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 5), name: "2 Abe Road", postcode: "AA1 1AA") + FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 6), name: "1 Abe Road", postcode: "AA1 2AA") + FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 7), name: "1 Lake Lane", postcode: "AA1 3AA") + FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 8), name: "3 Abe Road", postcode: "AA1 4AA") + FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 9), name: "2 Lake Lane", postcode: "AA1 5AA") + FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 10), name: "Smith Avenue", postcode: "AA1 6AA") + FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 11), name: "Abacus Road", postcode: "AA1 7AA") + FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 12), name: "Hawthorne Road", postcode: "AA1 8AA") lettings_log.update!(scheme:) end - it "orders the locations by name then numerically" do + it "orders the locations by postcode" do expect(question.displayed_answer_options(lettings_log).values.map { |v| v["hint"] }).to eq([ - "Abacus Road", - "1 Abe Road", "2 Abe Road", - "3 Abe Road", - "Hawthorne Road", + "1 Abe Road", "1 Lake Lane", + "3 Abe Road", "2 Lake Lane", "Smith Avenue", + "Abacus Road", + "Hawthorne Road", ]) end end