Browse Source

CLDC-1381-Postcode-display-formatting (#781)

pull/807/head
Ted-U 2 years ago committed by GitHub
parent
commit
6d0d40fb22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      app/models/case_log.rb
  2. 10
      app/models/location.rb
  3. 4
      app/models/scheme.rb
  4. 4
      app/services/imports/case_logs_import_service.rb
  5. 2
      spec/features/form/conditional_questions_spec.rb
  6. 4
      spec/features/schemes_helpers.rb
  7. 10
      spec/features/schemes_spec.rb
  8. 2
      spec/fixtures/exports/general_needs_log.csv
  9. 4
      spec/fixtures/exports/general_needs_log.xml
  10. 4
      spec/fixtures/exports/supported_housing_logs.xml
  11. 2
      spec/fixtures/files/case_logs_download.csv
  12. 14
      spec/models/case_log_spec.rb
  13. 4
      spec/models/location_spec.rb
  14. 6
      spec/requests/case_logs_controller_spec.rb
  15. 16
      spec/requests/locations_controller_spec.rb

19
app/models/case_log.rb

@ -8,7 +8,6 @@ class CaseLogValidator < ActiveModel::Validator
include Validations::TenancyValidations include Validations::TenancyValidations
include Validations::DateValidations include Validations::DateValidations
include Validations::LocalAuthorityValidations include Validations::LocalAuthorityValidations
def validate(record) def validate(record)
validation_methods = public_methods.select { |method| method.starts_with?("validate_") } validation_methods = public_methods.select { |method| method.starts_with?("validate_") }
validation_methods.each { |meth| public_send(meth, record) } validation_methods.each { |meth| public_send(meth, record) }
@ -57,7 +56,7 @@ class CaseLog < ApplicationRecord
scope :filter_by_id, ->(id) { where(id:) } scope :filter_by_id, ->(id) { where(id:) }
scope :filter_by_tenant_code, ->(tenant_code) { where("tenancycode ILIKE ?", "%#{tenant_code}%") } scope :filter_by_tenant_code, ->(tenant_code) { where("tenancycode ILIKE ?", "%#{tenant_code}%") }
scope :filter_by_propcode, ->(propcode) { where("propcode ILIKE ?", "%#{propcode}%") } scope :filter_by_propcode, ->(propcode) { where("propcode ILIKE ?", "%#{propcode}%") }
scope :filter_by_postcode, ->(postcode_full) { where("postcode_full ILIKE ?", "%#{postcode_full.gsub(/\s+/, '')}%") } scope :filter_by_postcode, ->(postcode_full) { where("REPLACE(postcode_full, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") }
scope :search_by, lambda { |param| scope :search_by, lambda { |param|
filter_by_id(param) filter_by_id(param)
.or(filter_by_tenant_code(param)) .or(filter_by_tenant_code(param))
@ -118,6 +117,22 @@ class CaseLog < ApplicationRecord
end end
end end
def postcode_full=(postcode)
if postcode
super UKPostcode.parse(postcode).to_s
else
super nil
end
end
def ppostcode_full=(postcode)
if postcode
super UKPostcode.parse(postcode).to_s
else
super nil
end
end
def completed? def completed?
status == "completed" status == "completed"
end end

10
app/models/location.rb

@ -9,7 +9,7 @@ class Location < ApplicationRecord
attr_accessor :add_another_location attr_accessor :add_another_location
scope :search_by_postcode, ->(postcode) { where("postcode ILIKE ?", "%#{postcode.gsub(/\s+/, '')}%") } scope :search_by_postcode, ->(postcode) { where("REPLACE(postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) } scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) }
@ -42,6 +42,14 @@ class Location < ApplicationRecord
] ]
end end
def postcode=(postcode)
if postcode
super UKPostcode.parse(postcode).to_s
else
super nil
end
end
private private
PIO = PostcodeService.new PIO = PostcodeService.new

4
app/models/scheme.rb

@ -8,8 +8,8 @@ class Scheme < ApplicationRecord
scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) } scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) }
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") }
scope :search_by_postcode, ->(postcode) { joins("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } scope :search_by_postcode, ->(postcode) { left_joins(:locations).where("REPLACE(locations.postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by_location_name, ->(name) { joins("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.name ILIKE ?", "%#{name}%") } scope :search_by_location_name, ->(name) { left_joins(:locations).where("locations.name ILIKE ?", "%#{name}%") }
scope :search_by, lambda { |param| scope :search_by, lambda { |param|
search_by_postcode(param) search_by_postcode(param)
.or(search_by_service_name(param)) .or(search_by_service_name(param))

4
app/services/imports/case_logs_import_service.rb

@ -442,10 +442,10 @@ module Imports
def compose_postcode(xml_doc, outcode, incode) def compose_postcode(xml_doc, outcode, incode)
outcode_value = string_or_nil(xml_doc, outcode) outcode_value = string_or_nil(xml_doc, outcode)
incode_value = string_or_nil(xml_doc, incode) incode_value = string_or_nil(xml_doc, incode)
if outcode_value.nil? || incode_value.nil? || !"#{outcode_value}#{incode_value}".match(POSTCODE_REGEXP) if outcode_value.nil? || incode_value.nil? || !"#{outcode_value} #{incode_value}".match(POSTCODE_REGEXP)
nil nil
else else
"#{outcode_value}#{incode_value}" "#{outcode_value} #{incode_value}"
end end
end end

2
spec/features/form/conditional_questions_spec.rb

@ -40,7 +40,7 @@ RSpec.describe "Form Conditional Questions" do
it "is displayed correctly" do it "is displayed correctly" do
case_log.update!(postcode_known: 1, postcode_full: "NW1 6RT") case_log.update!(postcode_known: 1, postcode_full: "NW1 6RT")
visit("/logs/#{id}/property-postcode") visit("/logs/#{id}/property-postcode")
expect(page).to have_field("case-log-postcode-full-field", with: "NW16RT") expect(page).to have_field("case-log-postcode-full-field", with: "NW1 6RT")
end end
end end
end end

4
spec/features/schemes_helpers.rb

@ -55,7 +55,7 @@ module SchemesHelpers
end end
def fill_in_and_save_location def fill_in_and_save_location
fill_in "Postcode", with: "AA1 1AA" fill_in "Postcode", with: "AA11AA"
fill_in "Location name (optional)", with: "Some name" fill_in "Location name (optional)", with: "Some name"
fill_in "Total number of units at this location", with: 5 fill_in "Total number of units at this location", with: 5
fill_in "Day", with: 2 fill_in "Day", with: 2
@ -68,7 +68,7 @@ module SchemesHelpers
end end
def fill_in_and_save_second_location def fill_in_and_save_second_location
fill_in "Postcode", with: "XX1 1XX" fill_in "Postcode", with: "AA12AA"
fill_in "Location name (optional)", with: "Other name" fill_in "Location name (optional)", with: "Other name"
fill_in "Total number of units at this location", with: 2 fill_in "Total number of units at this location", with: 2
choose "Self-contained house" choose "Self-contained house"

10
spec/features/schemes_spec.rb

@ -476,7 +476,7 @@ RSpec.describe "Schemes scheme Features" do
end end
it "displays information about the first created location" do it "displays information about the first created location" do
expect(page).to have_content "AA11AA" expect(page).to have_content "AA1 1AA"
expect(page).to have_content "Some name" expect(page).to have_content "Some name"
expect(page).to have_content "5" expect(page).to have_content "5"
expect(page).to have_content "Self-contained house" expect(page).to have_content "Self-contained house"
@ -493,7 +493,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays information about newly created location" do it "displays information about newly created location" do
click_link "Add a location" click_link "Add a location"
fill_in_and_save_second_location fill_in_and_save_second_location
expect(page).to have_content "XX11XX" expect(page).to have_content "AA1 2AA"
expect(page).to have_content "Other name" expect(page).to have_content "Other name"
expect(page).to have_content "Self-contained house" expect(page).to have_content "Self-contained house"
end end
@ -507,13 +507,13 @@ RSpec.describe "Schemes scheme Features" do
end end
it "displays changed location" do it "displays changed location" do
click_link "XX11XX" click_link "AA1 2AA"
fill_in "Postcode", with: "ZZ1 1ZZ" fill_in "Postcode", with: "AA1 3AA"
choose "location-mobility-type-wheelchair-user-standard-field" choose "location-mobility-type-wheelchair-user-standard-field"
click_button "Save and continue" click_button "Save and continue"
expect(page).to have_content "Locations" expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} location" expect(page).to have_content "#{scheme.locations.count} location"
expect(page).to have_content "ZZ11ZZ" expect(page).to have_content "AA1 3AA"
end end
end end

2
spec/fixtures/exports/general_needs_log.csv vendored

@ -1,2 +1,2 @@
status,tenancycode,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,ppcodenk,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,sheltered,hhtype,new_old,vacdays,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate status,tenancycode,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,ppcodenk,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,sheltered,hhtype,new_old,vacdays,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate
2,BZ737,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,1,5,1,SE26RT,6,7,3,2,1,68,1,1,2,2,1,NW15TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,2,200.0,50.0,40.0,35.0,325.0,12.0,,1,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,,4,2,638,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC 2,BZ737,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,1,5,1,SE2 6RT,6,7,3,2,1,68,1,1,2,2,1,NW1 5TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,2,200.0,50.0,40.0,35.0,325.0,12.0,,1,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,,4,2,638,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC

1 status tenancycode age1 sex1 ethnic national prevten ecstat1 hhmemb age2 sex2 ecstat2 age3 sex3 ecstat3 age4 sex4 ecstat4 age5 sex5 ecstat5 age6 sex6 ecstat6 age7 sex7 ecstat7 age8 sex8 ecstat8 homeless underoccupation_benefitcap leftreg reservist illness preg_occ startertenancy tenancylength tenancy ppostcode_full rsnvac unittype_gn beds offered wchair earnings incfreq benefits period layear waityear postcode_full reasonpref cbl chr cap reasonother housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_g housingneeds_h illness_type_1 illness_type_2 illness_type_3 illness_type_4 illness_type_8 illness_type_5 illness_type_6 illness_type_7 illness_type_9 illness_type_10 rp_homeless rp_insan_unsat rp_medwel rp_hardship rp_dontknow tenancyother irproduct_other reason propcode la prevloc hb hbrentshortfall mrcdate incref startdate armedforces unitletas builtype voiddate renttype needstype lettype totchild totelder totadult nocharge referral brent scharge pscharge supcharg tcharge tshortfall chcharge ppcodenk has_benefits renewal wrent wscharge wpschrge wsupchrg wtcharge wtshortfall refused housingneeds wchchrg newprop relat2 relat3 relat4 relat5 relat6 relat7 relat8 lar irproduct joint sheltered hhtype new_old vacdays form owningorgid owningorgname hcnum maningorgid maningorgname manhcnum createddate uploaddate
2 2 BZ737 35 F 2 4 6 0 2 32 M 6 1 0 1 0 1 2 1 5 1 SE26RT SE2 6RT 6 7 3 2 1 68 1 1 2 2 1 NW15TY NW1 5TY 1 1 1 2 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 4 123 E09000003 E07000105 6 1 2020-05-05 10:36:49 UTC 0 2022-02-02 10:36:49 UTC 1 2 1 2019-11-03 00:00:00 UTC 2 1 7 0 0 2 0 2 200.0 50.0 40.0 35.0 325.0 12.0 1 1 0 100.0 25.0 20.0 17.5 162.5 6.0 0 1 2 P 4 2 638 {id} {owning_org_id} DLUHC 1234 {managing_org_id} DLUHC 1234 2022-02-08 16:52:15 UTC 2022-02-08 16:52:15 UTC

4
spec/fixtures/exports/general_needs_log.xml vendored

@ -40,7 +40,7 @@
<startertenancy>1</startertenancy> <startertenancy>1</startertenancy>
<tenancylength>5</tenancylength> <tenancylength>5</tenancylength>
<tenancy>1</tenancy> <tenancy>1</tenancy>
<ppostcode_full>SE26RT</ppostcode_full> <ppostcode_full>SE2 6RT</ppostcode_full>
<rsnvac>6</rsnvac> <rsnvac>6</rsnvac>
<unittype_gn>7</unittype_gn> <unittype_gn>7</unittype_gn>
<beds>3</beds> <beds>3</beds>
@ -52,7 +52,7 @@
<period>2</period> <period>2</period>
<layear>2</layear> <layear>2</layear>
<waityear>1</waityear> <waityear>1</waityear>
<postcode_full>NW15TY</postcode_full> <postcode_full>NW1 5TY</postcode_full>
<reasonpref>1</reasonpref> <reasonpref>1</reasonpref>
<cbl>1</cbl> <cbl>1</cbl>
<chr>1</chr> <chr>1</chr>

4
spec/fixtures/exports/supported_housing_logs.xml vendored

@ -40,7 +40,7 @@
<startertenancy>1</startertenancy> <startertenancy>1</startertenancy>
<tenancylength/> <tenancylength/>
<tenancy>1</tenancy> <tenancy>1</tenancy>
<ppostcode_full>LE51QP</ppostcode_full> <ppostcode_full>LE5 1QP</ppostcode_full>
<rsnvac>6</rsnvac> <rsnvac>6</rsnvac>
<beds/> <beds/>
<offered>2</offered> <offered>2</offered>
@ -51,7 +51,7 @@
<period>2</period> <period>2</period>
<layear>2</layear> <layear>2</layear>
<waityear>1</waityear> <waityear>1</waityear>
<postcode_full>SW1A2AA</postcode_full> <postcode_full>SW1A 2AA</postcode_full>
<reasonpref>1</reasonpref> <reasonpref>1</reasonpref>
<cbl>1</cbl> <cbl>1</cbl>
<chr>1</chr> <chr>1</chr>

2
spec/fixtures/files/case_logs_download.csv vendored

@ -1,2 +1,2 @@
id,status,created_at,updated_at,tenancycode,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,net_income_value_check,property_owner_organisation,property_manager_organisation,sale_or_letting,irproduct_other,purchaser_code,reason,propcode,majorrepairs,la,prevloc,hb,hbrentshortfall,property_relet,mrcdate,incref,sale_completion_date,startdate,armedforces,first_time_property_let_as_social_housing,unitletas,builtype,voiddate,owning_organisation_id,managing_organisation_id,renttype,needstype,lettype,postcode_known,is_la_inferred,totchild,totelder,totadult,net_income_known,nocharge,is_carehome,household_charge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,declaration,ppcodenk,previous_la_known,is_previous_la_inferred,age1_known,age2_known,age3_known,age4_known,age5_known,age6_known,age7_known,age8_known,ethnic_group,ethnic_other,letting_allocation_unknown,details_known_2,details_known_3,details_known_4,details_known_5,details_known_6,details_known_7,details_known_8,rent_type,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,rent_value_check,old_form_id,lar,irproduct,old_id,joint,created_by_id,illness_type_0,retirement_value_check,tshortfall_known,sheltered,pregnancy_value_check,hhtype,new_old,vacdays,scheme_id,location_id,unittype_sh id,status,created_at,updated_at,tenancycode,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,net_income_value_check,property_owner_organisation,property_manager_organisation,sale_or_letting,irproduct_other,purchaser_code,reason,propcode,majorrepairs,la,prevloc,hb,hbrentshortfall,property_relet,mrcdate,incref,sale_completion_date,startdate,armedforces,first_time_property_let_as_social_housing,unitletas,builtype,voiddate,owning_organisation_id,managing_organisation_id,renttype,needstype,lettype,postcode_known,is_la_inferred,totchild,totelder,totadult,net_income_known,nocharge,is_carehome,household_charge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,declaration,ppcodenk,previous_la_known,is_previous_la_inferred,age1_known,age2_known,age3_known,age4_known,age5_known,age6_known,age7_known,age8_known,ethnic_group,ethnic_other,letting_allocation_unknown,details_known_2,details_known_3,details_known_4,details_known_5,details_known_6,details_known_7,details_known_8,rent_type,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,rent_value_check,old_form_id,lar,irproduct,old_id,joint,created_by_id,illness_type_0,retirement_value_check,tshortfall_known,sheltered,pregnancy_value_check,hhtype,new_old,vacdays,scheme_id,location_id,unittype_sh
{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Westminster,,,,,,,,,,,,,,DLUHC,{owning_org_id},,Supported housing,,,false,0,0,0,,0,,,,,,,,,,,,,,false,,,,,,,,,,,,,,,,,,,,0,,,,,,,,0,,,,,,,,,,,,,,,,,Danny Rojas,,,,,,9,,,{scheme_id},SE11TE,6 {id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Westminster,,,,,,,,,,,,,,DLUHC,{owning_org_id},,Supported housing,,,false,0,0,0,,0,,,,,,,,,,,,,,false,,,,,,,,,,,,,,,,,,,,0,,,,,,,,0,,,,,,,,,,,,,,,,,Danny Rojas,,,,,,9,,,{scheme_id},SE1 1TE,6

1 id status created_at updated_at tenancycode age1 sex1 ethnic national prevten ecstat1 hhmemb age2 sex2 ecstat2 age3 sex3 ecstat3 age4 sex4 ecstat4 age5 sex5 ecstat5 age6 sex6 ecstat6 age7 sex7 ecstat7 age8 sex8 ecstat8 homeless underoccupation_benefitcap leftreg reservist illness preg_occ startertenancy tenancylength tenancy ppostcode_full rsnvac unittype_gn beds offered wchair earnings incfreq benefits period layear waityear postcode_full reasonpref cbl chr cap reasonother housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_g housingneeds_h illness_type_1 illness_type_2 illness_type_3 illness_type_4 illness_type_8 illness_type_5 illness_type_6 illness_type_7 illness_type_9 illness_type_10 rp_homeless rp_insan_unsat rp_medwel rp_hardship rp_dontknow tenancyother net_income_value_check property_owner_organisation property_manager_organisation sale_or_letting irproduct_other purchaser_code reason propcode majorrepairs la prevloc hb hbrentshortfall property_relet mrcdate incref sale_completion_date startdate armedforces first_time_property_let_as_social_housing unitletas builtype voiddate owning_organisation_id managing_organisation_id renttype needstype lettype postcode_known is_la_inferred totchild totelder totadult net_income_known nocharge is_carehome household_charge referral brent scharge pscharge supcharg tcharge tshortfall chcharge declaration ppcodenk previous_la_known is_previous_la_inferred age1_known age2_known age3_known age4_known age5_known age6_known age7_known age8_known ethnic_group ethnic_other letting_allocation_unknown details_known_2 details_known_3 details_known_4 details_known_5 details_known_6 details_known_7 details_known_8 rent_type has_benefits renewal wrent wscharge wpschrge wsupchrg wtcharge wtshortfall refused housingneeds wchchrg newprop relat2 relat3 relat4 relat5 relat6 relat7 relat8 rent_value_check old_form_id lar irproduct old_id joint created_by_id illness_type_0 retirement_value_check tshortfall_known sheltered pregnancy_value_check hhtype new_old vacdays scheme_id location_id unittype_sh
2 {id} in_progress 2022-02-08 16:52:15 +0000 2022-02-08 16:52:15 +0000 2 Westminster DLUHC {owning_org_id} Supported housing false 0 0 0 0 false 0 0 Danny Rojas 9 {scheme_id} SE11TE SE1 1TE 6

14
spec/models/case_log_spec.rb

@ -1113,14 +1113,14 @@ RSpec.describe CaseLog do
def check_postcode_fields(postcode_field) def check_postcode_fields(postcode_field)
record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from case_logs where id=#{address_case_log.id}").to_a[0]
expect(address_case_log[postcode_field]).to eq("M11AE") expect(address_case_log[postcode_field]).to eq("M1 1AE")
expect(record_from_db[postcode_field]).to eq("M11AE") expect(record_from_db[postcode_field]).to eq("M1 1AE")
end end
def check_previous_postcode_fields(postcode_field) def check_previous_postcode_fields(postcode_field)
record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from case_logs where id=#{address_case_log.id}").to_a[0]
expect(address_case_log[postcode_field]).to eq("M11AE") expect(address_case_log[postcode_field]).to eq("M1 1AE")
expect(record_from_db[postcode_field]).to eq("M11AE") expect(record_from_db[postcode_field]).to eq("M1 1AE")
end end
context "when saving addresses" do context "when saving addresses" do
@ -1205,7 +1205,7 @@ RSpec.describe CaseLog do
address_case_log.update!({ postcode_known: 1, postcode_full: "M1 1AD" }) address_case_log.update!({ postcode_known: 1, postcode_full: "M1 1AD" })
record_from_db = ActiveRecord::Base.connection.execute("select la, postcode_full from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select la, postcode_full from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["postcode_full"]).to eq("M11AD") expect(record_from_db["postcode_full"]).to eq("M1 1AD")
expect(address_case_log.la).to eq("E08000003") expect(address_case_log.la).to eq("E08000003")
expect(record_from_db["la"]).to eq("E08000003") expect(record_from_db["la"]).to eq("E08000003")
end end
@ -1295,7 +1295,7 @@ RSpec.describe CaseLog do
address_case_log.update!({ ppcodenk: 0, ppostcode_full: "M1 1AD" }) address_case_log.update!({ ppcodenk: 0, ppostcode_full: "M1 1AD" })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["ppostcode_full"]).to eq("M11AD") expect(record_from_db["ppostcode_full"]).to eq("M1 1AD")
expect(address_case_log.prevloc).to eq("E08000003") expect(address_case_log.prevloc).to eq("E08000003")
expect(record_from_db["prevloc"]).to eq("E08000003") expect(record_from_db["prevloc"]).to eq("E08000003")
end end
@ -1717,7 +1717,7 @@ RSpec.describe CaseLog do
it "correctly infers and saves postcode" do it "correctly infers and saves postcode" do
record_from_db = ActiveRecord::Base.connection.execute("SELECT postcode_full from case_logs WHERE id=#{supported_housing_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("SELECT postcode_full from case_logs WHERE id=#{supported_housing_case_log.id}").to_a[0]
expect(record_from_db["postcode_full"]).to be_nil expect(record_from_db["postcode_full"]).to be_nil
expect(supported_housing_case_log.postcode_full).to eq("M11AE") expect(supported_housing_case_log.postcode_full).to eq("M1 1AE")
end end
it "unittype_sh method returns the type_of_unit of the location" do it "unittype_sh method returns the type_of_unit of the location" do

4
spec/models/location_spec.rb

@ -72,8 +72,8 @@ RSpec.describe Location, type: :model do
describe "scopes" do describe "scopes" do
before do before do
FactoryBot.create(:location, name: "ABC", postcode: "NW18RR") FactoryBot.create(:location, name: "ABC", postcode: "NW1 8RR")
FactoryBot.create(:location, name: "XYZ", postcode: "SE16HJ") FactoryBot.create(:location, name: "XYZ", postcode: "SE1 6HJ")
end end
context "when searching by name" do context "when searching by name" do

6
spec/requests/case_logs_controller_spec.rb

@ -30,7 +30,7 @@ RSpec.describe CaseLogsController, type: :request do
let(:age1) { 35 } let(:age1) { 35 }
let(:offered) { 12 } let(:offered) { 12 }
let(:period) { 2 } let(:period) { 2 }
let(:postcode_full) { "SE116TY" } let(:postcode_full) { "SE11 6TY" }
let(:in_progress) { "in_progress" } let(:in_progress) { "in_progress" }
let(:completed) { "completed" } let(:completed) { "completed" }
@ -831,7 +831,7 @@ RSpec.describe CaseLogsController, type: :request do
it "updates the case log with the given fields and keeps original values where none are passed" do it "updates the case log with the given fields and keeps original values where none are passed" do
case_log.reload case_log.reload
expect(case_log.tenancycode).to eq("New Value") expect(case_log.tenancycode).to eq("New Value")
expect(case_log.postcode_full).to eq("M11AE") expect(case_log.postcode_full).to eq("M1 1AE")
end end
context "with an invalid case log id" do context "with an invalid case log id" do
@ -889,7 +889,7 @@ RSpec.describe CaseLogsController, type: :request do
it "updates the case log with the given fields and keeps original values where none are passed" do it "updates the case log with the given fields and keeps original values where none are passed" do
case_log.reload case_log.reload
expect(case_log.tenancycode).to eq("New Value") expect(case_log.tenancycode).to eq("New Value")
expect(case_log.postcode_full).to eq("SW1A2AA") expect(case_log.postcode_full).to eq("SW1A 2AA")
end end
context "with an invalid case log id" do context "with an invalid case log id" do

16
spec/requests/locations_controller_spec.rb

@ -108,7 +108,7 @@ RSpec.describe LocationsController, type: :request do
it "creates a new location for scheme with valid params" do it "creates a new location for scheme with valid params" do
expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ1 1ZZ")
expect(Location.last.units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.startdate).to eq(startdate) expect(Location.last.startdate).to eq(startdate)
@ -119,7 +119,7 @@ RSpec.describe LocationsController, type: :request do
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", mobility_type: "N" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", mobility_type: "N" } } }
it "creates a new location for scheme with postcode " do it "creates a new location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ1 1ZZ")
end end
end end
@ -286,7 +286,7 @@ RSpec.describe LocationsController, type: :request do
it "creates a new location for scheme with valid params" do it "creates a new location for scheme with valid params" do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ1 1ZZ")
expect(Location.last.units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
end end
@ -295,7 +295,7 @@ RSpec.describe LocationsController, type: :request do
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", mobility_type: "N" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", mobility_type: "N" } } }
it "creates a new location for scheme with postcode " do it "creates a new location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ1 1ZZ")
end end
end end
@ -526,7 +526,7 @@ RSpec.describe LocationsController, type: :request do
it "updates existing location for scheme with valid params" do it "updates existing location for scheme with valid params" do
expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ1 1ZZ")
expect(Location.last.units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.startdate).to eq(startdate) expect(Location.last.startdate).to eq(startdate)
@ -550,7 +550,7 @@ RSpec.describe LocationsController, type: :request do
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } }
it "updates existing location for scheme with postcode " do it "updates existing location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ1 1ZZ")
end end
end end
@ -657,7 +657,7 @@ RSpec.describe LocationsController, type: :request do
it "updates existing location for scheme with valid params" do it "updates existing location for scheme with valid params" do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ1 1ZZ")
expect(Location.last.units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
end end
@ -680,7 +680,7 @@ RSpec.describe LocationsController, type: :request do
let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } }
it "updates a location for scheme with postcode " do it "updates a location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ1 1ZZ")
end end
end end

Loading…
Cancel
Save