Browse Source

Prevents location from being cleared when it has been changed alongside the scheme

pull/748/head
Stéphane Meny 3 years ago
parent
commit
af58145a1b
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 6
      app/models/case_log.rb
  2. 12
      app/models/derived_variables/case_log_variables.rb
  3. 7
      spec/services/imports/case_logs_import_service_spec.rb

6
app/models/case_log.rb

@ -23,7 +23,7 @@ class CaseLog < ApplicationRecord
validates_with CaseLogValidator
before_validation :recalculate_start_year!, if: :startdate_changed?
before_validation :reset_scheme_location!, if: :scheme_changed?
before_validation :reset_scheme_location!, if: :scheme_changed?, unless: :location_changed?
before_validation :process_postcode_changes!, if: :postcode_full_changed?
before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed?
before_validation :reset_invalidated_dependent_fields!
@ -696,8 +696,4 @@ private
def upcase_and_remove_whitespace(string)
string.present? ? string.upcase.gsub(/\s+/, "") : string
end
def reset_scheme_location!
self.location = nil
end
end

12
app/models/derived_variables/case_log_variables.rb

@ -68,10 +68,7 @@ module DerivedVariables::CaseLogVariables
self.new_old = new_or_existing_tenant
self.vacdays = property_vacant_days
if is_supported_housing? && scheme
if scheme.locations.size == 1
self.location = scheme.locations.first
end
if is_supported_housing?
if location
# TODO: Remove and replace with mobility type
self.wchair = location.wheelchair_adaptation_before_type_cast
@ -189,4 +186,11 @@ private
(startdate - voiddate).to_i / 1.day
end
end
def reset_scheme_location!
self.location = nil
if scheme && scheme.locations.size == 1
self.location = scheme.locations.first
end
end
end

7
spec/services/imports/case_logs_import_service_spec.rb

@ -28,11 +28,12 @@ RSpec.describe Imports::CaseLogsImportService do
# Scheme and Location
scheme = FactoryBot.create(:scheme, old_visible_id: 123)
FactoryBot.create(:location,
locations = FactoryBot.create_list(:location, 3, scheme_id: scheme.id)
locations[0].update!(
old_visible_id: 10,
scheme_id: scheme.id,
wheelchair_adaptation: 1,
postcode: "LS166FT")
postcode: "LS166FT"
)
# Stub the form handler to use the real form
allow(FormHandler.instance).to receive(:get_form).with("2021_2022").and_return(real_2021_2022_form)

Loading…
Cancel
Save