Browse Source

Revert "CLDC-4340: Account for nil location name on location select (#3268)" (#3280)

This reverts commit dc1f25f722.
revert-3280-revert-3268-CLDC-4340-fix-location-id-question-with-nil-name
Samuel Young 6 days ago committed by GitHub
parent
commit
0a10512dc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      app/models/form/lettings/questions/location_id.rb
  2. 26
      spec/models/form/lettings/questions/location_id_spec.rb

7
app/models/form/lettings/questions/location_id.rb

@ -30,8 +30,11 @@ class Form::Lettings::Questions::LocationId < ::Form::Question
scheme_location_ids = lettings_log.scheme.locations.visible.confirmed.pluck(:id) scheme_location_ids = lettings_log.scheme.locations.visible.confirmed.pluck(:id)
answer_options.select { |k, _v| scheme_location_ids.include?(k.to_i) } answer_options.select { |k, _v| scheme_location_ids.include?(k.to_i) }
.sort_by { |_, v| v["value"] } .sort_by { |_, v|
.to_h name = v["hint"].match(/[a-zA-Z].*/).to_s
number = v["hint"].match(/\d+/).to_s.to_i
[name, number]
}.to_h
end end
def hidden_in_check_answers?(lettings_log, _current_user = nil) def hidden_in_check_answers?(lettings_log, _current_user = nil)

26
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 context "and some locations start with numbers" do
before do before do
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, 5), name: "2 Abe Road")
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, 6), name: "1 Abe Road")
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, 7), name: "1 Lake Lane")
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, 8), name: "3 Abe Road")
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, 9), name: "2 Lake Lane")
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, 10), name: "Smith Avenue")
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, 11), name: "Abacus Road")
FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 12), name: "Hawthorne Road", postcode: "AA1 8AA") FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 12), name: "Hawthorne Road")
lettings_log.update!(scheme:) lettings_log.update!(scheme:)
end end
it "orders the locations by postcode" do it "orders the locations by name then numerically" do
expect(question.displayed_answer_options(lettings_log).values.map { |v| v["hint"] }).to eq([ expect(question.displayed_answer_options(lettings_log).values.map { |v| v["hint"] }).to eq([
"2 Abe Road", "Abacus Road",
"1 Abe Road", "1 Abe Road",
"1 Lake Lane", "2 Abe Road",
"3 Abe Road", "3 Abe Road",
"Hawthorne Road",
"1 Lake Lane",
"2 Lake Lane", "2 Lake Lane",
"Smith Avenue", "Smith Avenue",
"Abacus Road",
"Hawthorne Road",
]) ])
end end
end end

Loading…
Cancel
Save