Browse Source

Do not display deleted locationa as an option

pull/2285/head
Kat 2 years ago
parent
commit
6c1ab0d44a
  1. 4
      app/models/form/lettings/questions/location_id.rb
  2. 12
      spec/models/form/lettings/questions/location_id_spec.rb

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

@ -20,7 +20,7 @@ class Form::Lettings::Questions::LocationId < ::Form::Question
answer_opts = {}
return answer_opts unless ActiveRecord::Base.connected?
Location.started_in_2_weeks.select(:id, :postcode, :name).each_with_object(answer_opts) do |location, hsh|
Location.visible.started_in_2_weeks.select(:id, :postcode, :name).each_with_object(answer_opts) do |location, hsh|
hsh[location.id.to_s] = { "value" => location.postcode, "hint" => location.name }
hsh
end
@ -29,7 +29,7 @@ class Form::Lettings::Questions::LocationId < ::Form::Question
def displayed_answer_options(lettings_log, _user = nil)
return {} unless lettings_log.scheme
scheme_location_ids = lettings_log.scheme.locations.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) }
end

12
spec/models/form/lettings/questions/location_id_spec.rb

@ -80,6 +80,18 @@ RSpec.describe Form::Lettings::Questions::LocationId, type: :model do
end
end
context "and all the locations are deleted" do
before do
FactoryBot.create(:location, scheme:, discarded_at: Time.utc(2022, 5, 12))
FactoryBot.create(:location, scheme:, discarded_at: Time.utc(2022, 5, 12))
lettings_log.update!(scheme:)
end
it "the displayed_answer_options is an empty hash" do
expect(question.displayed_answer_options(lettings_log)).to eq({})
end
end
context "and all but one of the locations have a startdate more than 2 weeks in the future" do
before do
FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 13))

Loading…
Cancel
Save