Browse Source

reset values if la cannot be inferred

pull/165/head
Kat 4 years ago
parent
commit
240f885e50
  1. 12
      app/models/case_log.rb
  2. 16
      spec/models/case_log_spec.rb

12
app/models/case_log.rb

@ -201,14 +201,16 @@ private
self.renttype = RENT_TYPE_MAPPING[rent_type]
self.lettype = "#{renttype} #{needstype} #{owning_organisation['Org type']}" if renttype.present? && needstype.present? && owning_organisation["Org type"].present?
self.is_la_inferred = false if is_la_inferred.nil?
self.la = get_la(property_postcode) if property_postcode.present?
self.la = get_la(property_postcode)
end
def get_la(postcode)
postcode_lookup = PIO.lookup(postcode)
unless postcode_lookup.info.nil?
self.is_la_inferred = true
return postcode_lookup.admin_district
if postcode.present?
postcode_lookup = PIO.lookup(postcode)
if postcode_lookup && postcode_lookup.info.present?
self.is_la_inferred = true
return postcode_lookup.admin_district
end
end
self.la = nil
self.is_la_inferred = false

16
spec/models/case_log_spec.rb

@ -1042,6 +1042,22 @@ RSpec.describe Form, type: :model do
expect(address_case_log.la).to eq("Manchester")
expect(record_from_db["la"]).to eq("E08000003")
end
it "correctly resets all fields" do
address_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select la from case_logs where id=#{address_case_log.id}").to_a[0]
expect(address_case_log.la).to eq("Manchester")
expect(record_from_db["la"]).to eq("E08000003")
address_case_log.update!({ property_postcode: "" })
address_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["property_postcode"]).to eq("")
expect(address_case_log.la).to eq(nil)
expect(record_from_db["la"]).to eq(nil)
end
end
end
end

Loading…
Cancel
Save