Browse Source

Deleted extra postcode and date fields

pull/470/head
Stéphane Meny 3 years ago
parent
commit
6ac59337a2
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 14
      app/models/bulk_upload.rb
  2. 26
      app/models/case_log.rb
  3. 12
      app/models/validations/date_validations.rb
  4. 4
      app/models/validations/household_validations.rb
  5. 4
      docs/api/DLUHC-CORE-Data.v1.json
  6. 13
      spec/factories/case_log.rb
  7. 10
      spec/fixtures/complete_case_log.json
  8. 15
      spec/fixtures/exports/case_logs.xml
  9. 34
      spec/models/case_log_spec.rb
  10. 2
      spec/models/form_spec.rb
  11. 24
      spec/models/validations/date_validations_spec.rb
  12. 18
      spec/models/validations/household_validations_spec.rb
  13. 4
      spec/requests/form_controller_spec.rb

14
app/models/bulk_upload.rb

@ -110,7 +110,7 @@ class BulkUpload
earnings: row[50], earnings: row[50],
# increfused: row[51], # increfused: row[51],
reason: row[52], reason: row[52],
other_reason_for_leaving_last_settled_home: row[53], reasonother: row[53],
underoccupation_benefitcap: row[54], underoccupation_benefitcap: row[54],
housingneeds_a: row[55], housingneeds_a: row[55],
housingneeds_b: row[56], housingneeds_b: row[56],
@ -120,8 +120,6 @@ class BulkUpload
housingneeds_h: row[60], housingneeds_h: row[60],
prevten: row[61], prevten: row[61],
prevloc: row[62], prevloc: row[62],
# ppostc1: row[63],
# ppostc2: row[64],
# prevpco_unknown: row[65], # prevpco_unknown: row[65],
layear: row[66], layear: row[66],
waityear: row[67], waityear: row[67],
@ -146,15 +144,9 @@ class BulkUpload
# no_rent_or_charge: row[86], # no_rent_or_charge: row[86],
hbrentshortfall: row[87], hbrentshortfall: row[87],
tshortfall: row[88], tshortfall: row[88],
property_void_date: row[89].to_s + row[90].to_s + row[91].to_s, voiddate: row[89].to_s + row[90].to_s + row[91].to_s,
# property_void_date_day: row[89],
# property_void_date_month: row[90],
# property_void_date_year: row[91],
majorrepairs: row[92].present? ? "1" : nil, majorrepairs: row[92].present? ? "1" : nil,
mrcdate: row[92].to_s + row[93].to_s + row[94].to_s, mrcdate: row[92].to_s + row[93].to_s + row[94].to_s,
mrcday: row[92],
mrcmonth: row[93],
mrcyear: row[94],
# supported_scheme: row[95], # supported_scheme: row[95],
startdate: date_time(row[98], row[97], row[96]), startdate: date_time(row[98], row[97], row[96]),
# startdate_day: row[96], # startdate_day: row[96],
@ -169,8 +161,6 @@ class BulkUpload
property_relet: row[105], property_relet: row[105],
rsnvac: row[106], rsnvac: row[106],
la: row[107], la: row[107],
# postcode: row[108],
# postcod2: row[109],
# row[110] removed # row[110] removed
# row[111] is owning organisation used above # row[111] is owning organisation used above
# username: row[112], # username: row[112],

26
app/models/case_log.rb

@ -379,16 +379,6 @@ private
end end
def set_derived_fields! def set_derived_fields!
if mrcdate.present?
self.mrcday = mrcdate.day
self.mrcmonth = mrcdate.month
self.mrcyear = mrcdate.year
end
if property_void_date.present?
self.vday = property_void_date.day
self.vmonth = property_void_date.month
self.vyear = property_void_date.year
end
if rsnvac.present? if rsnvac.present?
self.newprop = has_first_let_vacancy_reason? ? 1 : 2 self.newprop = has_first_let_vacancy_reason? ? 1 : 2
end end
@ -446,41 +436,37 @@ private
def process_postcode_changes! def process_postcode_changes!
self.postcode_full = postcode_full.present? ? postcode_full.upcase.gsub(/\s+/, "") : postcode_full self.postcode_full = postcode_full.present? ? postcode_full.upcase.gsub(/\s+/, "") : postcode_full
process_postcode(postcode_full, "postcode_known", "is_la_inferred", "la", "postcode", "postcod2") process_postcode(postcode_full, "postcode_known", "is_la_inferred", "la")
end end
def process_previous_postcode_changes! def process_previous_postcode_changes!
self.ppostcode_full = ppostcode_full.present? ? ppostcode_full.upcase.gsub(/\s+/, "") : ppostcode_full self.ppostcode_full = ppostcode_full.present? ? ppostcode_full.upcase.gsub(/\s+/, "") : ppostcode_full
process_postcode(ppostcode_full, "previous_postcode_known", "is_previous_la_inferred", "prevloc", nil, nil) process_postcode(ppostcode_full, "previous_postcode_known", "is_previous_la_inferred", "prevloc")
end end
def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key, outcode_key, incode_key) def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key)
return if postcode.blank? return if postcode.blank?
self[postcode_known_key] = 1 self[postcode_known_key] = 1
inferred_la = get_inferred_la(postcode) inferred_la = get_inferred_la(postcode)
self[la_inferred_key] = inferred_la.present? self[la_inferred_key] = inferred_la.present?
self[la_key] = inferred_la if inferred_la.present? self[la_key] = inferred_la if inferred_la.present?
self[outcode_key] = UKPostcode.parse(postcode).outcode unless outcode_key.nil?
self[incode_key] = UKPostcode.parse(postcode).incode unless incode_key.nil?
end end
def reset_location_fields! def reset_location_fields!
reset_location(is_la_inferred, "la", "is_la_inferred", "postcode_full", "postcode", "postcod2", la_known) reset_location(is_la_inferred, "la", "is_la_inferred", "postcode_full", la_known)
end end
def reset_previous_location_fields! def reset_previous_location_fields!
reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "ppostcode_full", nil, nil, previous_la_known) reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "ppostcode_full", previous_la_known)
end end
def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, incode_key, outcode_key, is_la_known) def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, is_la_known)
if is_inferred || is_la_known != 1 if is_inferred || is_la_known != 1
self[la_key] = nil self[la_key] = nil
end end
self[is_inferred_key] = false self[is_inferred_key] = false
self[postcode_key] = nil self[postcode_key] = nil
self[incode_key] = nil unless incode_key.nil?
self[outcode_key] = nil unless outcode_key.nil?
end end
def get_totelder def get_totelder

12
app/models/validations/date_validations.rb

@ -15,16 +15,16 @@ module Validations::DateValidations
end end
def validate_property_void_date(record) def validate_property_void_date(record)
if record["property_void_date"].present? && record["startdate"].present? && record["startdate"].to_date - record["property_void_date"].to_date > 3650 if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650
record.errors.add :property_void_date, I18n.t("validations.property.void_date.ten_years_before_tenancy_start") record.errors.add :voiddate, I18n.t("validations.property.void_date.ten_years_before_tenancy_start")
end end
if record["property_void_date"].present? && record["startdate"].present? && record["startdate"].to_date < record["property_void_date"].to_date if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date < record["voiddate"].to_date
record.errors.add :property_void_date, I18n.t("validations.property.void_date.before_tenancy_start") record.errors.add :voiddate, I18n.t("validations.property.void_date.before_tenancy_start")
end end
if record["property_void_date"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["property_void_date"].to_date if record["voiddate"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date
record.errors.add :property_void_date, I18n.t("validations.property.void_date.after_mrcdate") record.errors.add :voiddate, I18n.t("validations.property.void_date.after_mrcdate")
end end
end end

4
app/models/validations/household_validations.rb

@ -18,7 +18,7 @@ module Validations::HouseholdValidations
record.errors.add :underoccupation_benefitcap, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required") record.errors.add :underoccupation_benefitcap, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required")
record.errors.add :reason, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required") record.errors.add :reason, I18n.t("validations.household.underoccupation_benefitcap.dont_know_required")
end end
validate_other_field(record, 31, :reason, :other_reason_for_leaving_last_settled_home) validate_other_field(record, 31, :reason, :reasonother)
if record.is_reason_permanently_decanted? && record.referral.present? && !record.is_internal_transfer? if record.is_reason_permanently_decanted? && record.referral.present? && !record.is_internal_transfer?
record.errors.add :referral, I18n.t("validations.household.referral.reason_permanently_decanted") record.errors.add :referral, I18n.t("validations.household.referral.reason_permanently_decanted")
@ -56,7 +56,7 @@ module Validations::HouseholdValidations
end end
def validate_accessibility_requirements(record) def validate_accessibility_requirements(record)
all_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c, record.housingneeds_f, record.housingneeds_g, record.housingneeds_h, record.accessibility_requirements_prefer_not_to_say] all_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c, record.housingneeds_f, record.housingneeds_g, record.housingneeds_h]
if all_options.count(1) > 1 if all_options.count(1) > 1
mobility_accessibility_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c] mobility_accessibility_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c]
unless all_options.count(1) == 2 && record.housingneeds_f == 1 && mobility_accessibility_options.any? { |x| x == 1 } unless all_options.count(1) == 2 && record.housingneeds_f == 1 && mobility_accessibility_options.any? { |x| x == 1 }

4
docs/api/DLUHC-CORE-Data.v1.json

@ -361,7 +361,7 @@
"cap": 0, "cap": 0,
"hbrentshortfall": 0, "hbrentshortfall": 0,
"tshortfall": 12, "tshortfall": 12,
"other_reason_for_leaving_last_settled_home": null, "reasonother": null,
"housingneeds_a": 1, "housingneeds_a": 1,
"housingneeds_b": 0, "housingneeds_b": 0,
"housingneeds_c": 0, "housingneeds_c": 0,
@ -940,4 +940,4 @@
} }
} }
} }
} }

13
spec/factories/case_log.rb

@ -34,7 +34,6 @@ FactoryBot.define do
trait :completed do trait :completed do
status { 2 } status { 2 }
tenant_code { "BZ737" } tenant_code { "BZ737" }
postcode { "NW1 7TY" }
age1 { 35 } age1 { 35 }
sex1 { "F" } sex1 { "F" }
ethnic { 2 } ethnic { 2 }
@ -61,10 +60,7 @@ FactoryBot.define do
rsnvac { 7 } rsnvac { 7 }
unittype_gn { 2 } unittype_gn { 2 }
beds { 3 } beds { 3 }
property_void_date { "03/11/2019" } voiddate { "03/11/2019" }
vday { 3 }
vmonth { 11 }
vyear { 2019 }
offered { 2 } offered { 2 }
wchair { 1 } wchair { 1 }
earnings { 68 } earnings { 68 }
@ -83,14 +79,13 @@ FactoryBot.define do
cbl { 1 } cbl { 1 }
chr { 1 } chr { 1 }
cap { 0 } cap { 0 }
other_reason_for_leaving_last_settled_home { nil } reasonother { nil }
housingneeds_a { 1 } housingneeds_a { 1 }
housingneeds_b { 0 } housingneeds_b { 0 }
housingneeds_c { 0 } housingneeds_c { 0 }
housingneeds_f { 0 } housingneeds_f { 0 }
housingneeds_g { 0 } housingneeds_g { 0 }
housingneeds_h { 0 } housingneeds_h { 0 }
accessibility_requirements_prefer_not_to_say { 0 }
illness_type_1 { 0 } illness_type_1 { 0 }
illness_type_2 { 1 } illness_type_2 { 1 }
illness_type_3 { 0 } illness_type_3 { 0 }
@ -123,12 +118,8 @@ FactoryBot.define do
hb { 6 } hb { 6 }
hbrentshortfall { 0 } hbrentshortfall { 0 }
tshortfall { 12 } tshortfall { 12 }
postcod2 { "w3" }
property_relet { 0 } property_relet { 0 }
mrcdate { Time.utc(2020, 5, 0o5, 10, 36, 49) } mrcdate { Time.utc(2020, 5, 0o5, 10, 36, 49) }
mrcday { mrcdate.day }
mrcmonth { mrcdate.month }
mrcyear { mrcdate.year }
incref { 0 } incref { 0 }
sale_completion_date { nil } sale_completion_date { nil }
startdate { Time.utc(2022, 2, 2, 10, 36, 49) } startdate { Time.utc(2022, 2, 2, 10, 36, 49) }

10
spec/fixtures/complete_case_log.json vendored

@ -58,15 +58,9 @@
"unittype_gn": 2, "unittype_gn": 2,
"property_building_type": "dummy", "property_building_type": "dummy",
"beds": 3, "beds": 3,
"property_void_date": "10/10/2020", "voiddate": "10/10/2020",
"vday": 10,
"vmonth": 10,
"vyear": 2020,
"majorrepairs": 1, "majorrepairs": 1,
"mrcdate": "11/11/2020", "mrcdate": "11/11/2020",
"mrcday": 11,
"mrcmonth": 11,
"mrcyear": 2020,
"offered": 2, "offered": 2,
"wchair": 1, "wchair": 1,
"net_income_known": 1, "net_income_known": 1,
@ -91,7 +85,7 @@
"cap": 0, "cap": 0,
"hbrentshortfall": 0, "hbrentshortfall": 0,
"tshortfall": 12, "tshortfall": 12,
"other_reason_for_leaving_last_settled_home": null, "reasonother": null,
"housingneeds_a": 1, "housingneeds_a": 1,
"housingneeds_b": 0, "housingneeds_b": 0,
"housingneeds_c": 0, "housingneeds_c": 0,

15
spec/fixtures/exports/case_logs.xml vendored

@ -56,20 +56,19 @@
<benefits>1</benefits> <benefits>1</benefits>
<period>2</period> <period>2</period>
<layear>2</layear> <layear>2</layear>
<lawaitlist>1</lawaitlist> <waityear>1</waityear>
<postcode_full>NW15TY</postcode_full> <postcode_full>NW15TY</postcode_full>
<reasonpref>1</reasonpref> <reasonpref>1</reasonpref>
<cbl>1</cbl> <cbl>1</cbl>
<chr>1</chr> <chr>1</chr>
<cap>0</cap> <cap>0</cap>
<other_reason_for_leaving_last_settled_home/> <reasonother/>
<housingneeds_a>1</housingneeds_a> <housingneeds_a>1</housingneeds_a>
<housingneeds_b>0</housingneeds_b> <housingneeds_b>0</housingneeds_b>
<housingneeds_c>0</housingneeds_c> <housingneeds_c>0</housingneeds_c>
<housingneeds_f>0</housingneeds_f> <housingneeds_f>0</housingneeds_f>
<housingneeds_g>0</housingneeds_g> <housingneeds_g>0</housingneeds_g>
<housingneeds_h>0</housingneeds_h> <housingneeds_h>0</housingneeds_h>
<accessibility_requirements_prefer_not_to_say>0</accessibility_requirements_prefer_not_to_say>
<illness_type_1>0</illness_type_1> <illness_type_1>0</illness_type_1>
<illness_type_2>1</illness_type_2> <illness_type_2>1</illness_type_2>
<illness_type_3>0</illness_type_3> <illness_type_3>0</illness_type_3>
@ -99,13 +98,8 @@
<prevloc>E07000105</prevloc> <prevloc>E07000105</prevloc>
<hb>6</hb> <hb>6</hb>
<hbrentshortfall>0</hbrentshortfall> <hbrentshortfall>0</hbrentshortfall>
<postcode>NW1</postcode>
<postcod2>5TY</postcod2>
<property_relet>0</property_relet> <property_relet>0</property_relet>
<mrcdate>2020-05-05 10:36:49 UTC</mrcdate> <mrcdate>2020-05-05 10:36:49 UTC</mrcdate>
<mrcday>5</mrcday>
<mrcmonth>5</mrcmonth>
<mrcyear>2020</mrcyear>
<incref>0</incref> <incref>0</incref>
<sale_completion_date/> <sale_completion_date/>
<startdate>2022-02-02 10:36:49 UTC</startdate> <startdate>2022-02-02 10:36:49 UTC</startdate>
@ -113,7 +107,7 @@
<first_time_property_let_as_social_housing/> <first_time_property_let_as_social_housing/>
<unitletas>2</unitletas> <unitletas>2</unitletas>
<builtype>1</builtype> <builtype>1</builtype>
<property_void_date>2019-11-03 00:00:00 UTC</property_void_date> <voiddate>2019-11-03 00:00:00 UTC</voiddate>
<owning_organisation_id>{owning_org_id}</owning_organisation_id> <owning_organisation_id>{owning_org_id}</owning_organisation_id>
<managing_organisation_id>{managing_org_id}</managing_organisation_id> <managing_organisation_id>{managing_org_id}</managing_organisation_id>
<renttype>2</renttype> <renttype>2</renttype>
@ -155,9 +149,6 @@
<wtshortfall>6.0</wtshortfall> <wtshortfall>6.0</wtshortfall>
<refused>0</refused> <refused>0</refused>
<housingneeds>1</housingneeds> <housingneeds>1</housingneeds>
<vday>3</vday>
<vmonth>11</vmonth>
<vyear>2019</vyear>
<wchchrg/> <wchchrg/>
<newprop>2</newprop> <newprop>2</newprop>
<relat2>P</relat2> <relat2>P</relat2>

34
spec/models/case_log_spec.rb

@ -200,7 +200,7 @@ RSpec.describe CaseLog do
ppostcode_full: "M2 2AE", ppostcode_full: "M2 2AE",
startdate: Time.gm(2021, 10, 10), startdate: Time.gm(2021, 10, 10),
mrcdate: Time.gm(2021, 5, 4), mrcdate: Time.gm(2021, 5, 4),
property_void_date: Time.gm(2021, 3, 3), voiddate: Time.gm(2021, 3, 3),
net_income_known: 2, net_income_known: 2,
hhmemb: 7, hhmemb: 7,
rent_type: 4, rent_type: 4,
@ -210,30 +210,18 @@ RSpec.describe CaseLog do
}) })
end end
it "correctly derives and saves partial and full postcodes" do
record_from_db = ActiveRecord::Base.connection.execute("select postcode, postcod2 from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["postcode"]).to eq("M1")
expect(record_from_db["postcod2"]).to eq("1AE")
end
it "correctly derives and saves partial and full major repairs date" do it "correctly derives and saves partial and full major repairs date" do
record_from_db = ActiveRecord::Base.connection.execute("select mrcday, mrcmonth, mrcyear, mrcdate from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select mrcdate from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["mrcdate"].day).to eq(4) expect(record_from_db["mrcdate"].day).to eq(4)
expect(record_from_db["mrcdate"].month).to eq(5) expect(record_from_db["mrcdate"].month).to eq(5)
expect(record_from_db["mrcdate"].year).to eq(2021) expect(record_from_db["mrcdate"].year).to eq(2021)
expect(record_from_db["mrcday"]).to eq(4)
expect(record_from_db["mrcmonth"]).to eq(5)
expect(record_from_db["mrcyear"]).to eq(2021)
end end
it "correctly derives and saves partial and full major property void date" do it "correctly derives and saves partial and full major property void date" do
record_from_db = ActiveRecord::Base.connection.execute("select vday, vmonth, vyear, property_void_date from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select voiddate from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["property_void_date"].day).to eq(3) expect(record_from_db["voiddate"].day).to eq(3)
expect(record_from_db["property_void_date"].month).to eq(3) expect(record_from_db["voiddate"].month).to eq(3)
expect(record_from_db["property_void_date"].year).to eq(2021) expect(record_from_db["voiddate"].year).to eq(2021)
expect(record_from_db["vday"]).to eq(3)
expect(record_from_db["vmonth"]).to eq(3)
expect(record_from_db["vyear"]).to eq(2021)
end end
it "correctly derives and saves incref" do it "correctly derives and saves incref" do
@ -1138,14 +1126,10 @@ RSpec.describe CaseLog do
end end
end end
def check_postcode_fields(postcode_field, outcode_field, incode_field) def check_postcode_fields(postcode_field)
record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field}, #{outcode_field}, #{incode_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("M11AE")
expect(record_from_db[postcode_field]).to eq("M11AE") expect(record_from_db[postcode_field]).to eq("M11AE")
expect(address_case_log[outcode_field]).to eq("M1")
expect(record_from_db[outcode_field]).to eq("M1")
expect(address_case_log[incode_field]).to eq("1AE")
expect(record_from_db[incode_field]).to eq("1AE")
end end
def check_previous_postcode_fields(postcode_field) def check_previous_postcode_fields(postcode_field)
@ -1169,7 +1153,7 @@ RSpec.describe CaseLog do
end end
def check_property_postcode_fields def check_property_postcode_fields
check_postcode_fields("postcode_full", "postcode", "postcod2") check_postcode_fields("postcode_full")
end end
it "correctly formats previous postcode" do it "correctly formats previous postcode" do

2
spec/models/form_spec.rb

@ -118,7 +118,7 @@ RSpec.describe Form, type: :model do
def answer_local_authority(case_log) def answer_local_authority(case_log)
case_log.layear = "1 year but under 2 years" case_log.layear = "1 year but under 2 years"
case_log.lawaitlist = "Less than 1 year" case_log.waityear = "Less than 1 year"
case_log.postcode_full = "NW1 5TY" case_log.postcode_full = "NW1 5TY"
case_log.reason = "Permanently decanted from another property owned by this landlord" case_log.reason = "Permanently decanted from another property owned by this landlord"
case_log.ppostcode_full = "SE2 6RT" case_log.ppostcode_full = "SE2 6RT"

24
spec/models/validations/date_validations_spec.rb

@ -102,48 +102,48 @@ RSpec.describe Validations::DateValidations do
describe "property void date" do describe "property void date" do
it "cannot be after the tenancy start date" do it "cannot be after the tenancy start date" do
record.startdate = Time.zone.local(2022, 1, 1) record.startdate = Time.zone.local(2022, 1, 1)
record.property_void_date = Time.zone.local(2022, 2, 1) record.voiddate = Time.zone.local(2022, 2, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.property.void_date.before_tenancy_start")) .to include(match I18n.t("validations.property.void_date.before_tenancy_start"))
end end
it "must be before the tenancy start date" do it "must be before the tenancy start date" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = Time.zone.local(2022, 2, 1)
record.property_void_date = Time.zone.local(2022, 1, 1) record.voiddate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"]).to be_empty expect(record.errors["voiddate"]).to be_empty
end end
it "cannot be more than 10 years before the tenancy start date" do it "cannot be more than 10 years before the tenancy start date" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = Time.zone.local(2022, 2, 1)
record.property_void_date = Time.zone.local(2012, 1, 1) record.voiddate = Time.zone.local(2012, 1, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.property.void_date.ten_years_before_tenancy_start")) .to include(match I18n.t("validations.property.void_date.ten_years_before_tenancy_start"))
end end
it "must be within 10 years of the tenancy start date" do it "must be within 10 years of the tenancy start date" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = Time.zone.local(2022, 2, 1)
record.property_void_date = Time.zone.local(2012, 3, 1) record.voiddate = Time.zone.local(2012, 3, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"]).to be_empty expect(record.errors["voiddate"]).to be_empty
end end
context "when major repairs have been carried out" do context "when major repairs have been carried out" do
it "cannot be after major repairs date" do it "cannot be after major repairs date" do
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = Time.zone.local(2022, 1, 1)
record.property_void_date = Time.zone.local(2022, 2, 1) record.voiddate = Time.zone.local(2022, 2, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.property.void_date.after_mrcdate")) .to include(match I18n.t("validations.property.void_date.after_mrcdate"))
end end
it "must be before major repairs date" do it "must be before major repairs date" do
record.mrcdate = Time.zone.local(2022, 2, 1) record.mrcdate = Time.zone.local(2022, 2, 1)
record.property_void_date = Time.zone.local(2022, 1, 1) record.voiddate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"]).to be_empty expect(record.errors["voiddate"]).to be_empty
end end
end end
end end

18
spec/models/validations/household_validations_spec.rb

@ -113,7 +113,7 @@ RSpec.describe Validations::HouseholdValidations do
describe "reason for leaving last settled home validations" do describe "reason for leaving last settled home validations" do
let(:field) { "validations.other_field_not_required" } let(:field) { "validations.other_field_not_required" }
let(:main_field_label) { "reason" } let(:main_field_label) { "reason" }
let(:other_field_label) { "other reason for leaving last settled home" } let(:other_field_label) { "reasonother" }
let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) } let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) }
context "when reason is other" do context "when reason is other" do
@ -121,34 +121,34 @@ RSpec.describe Validations::HouseholdValidations do
it "validates that a reason is provided" do it "validates that a reason is provided" do
record.reason = 31 record.reason = 31
record.other_reason_for_leaving_last_settled_home = nil record.reasonother = nil
household_validator.validate_reason_for_leaving_last_settled_home(record) household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["other_reason_for_leaving_last_settled_home"]) expect(record.errors["reasonother"])
.to include(match(expected_error)) .to include(match(expected_error))
end end
it "expects that a reason is provided" do it "expects that a reason is provided" do
record.reason = 31 record.reason = 31
record.other_reason_for_leaving_last_settled_home = "Some unusual reason" record.reasonother = "Some unusual reason"
household_validator.validate_reason_for_leaving_last_settled_home(record) household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["other_reason_for_leaving_last_settled_home"]).to be_empty expect(record.errors["reasonother"]).to be_empty
end end
end end
context "when reason is not other" do context "when reason is not other" do
it "validates that other reason is not provided" do it "validates that other reason is not provided" do
record.reason = 18 record.reason = 18
record.other_reason_for_leaving_last_settled_home = "Some other reason" record.reasonother = "Some other reason"
household_validator.validate_reason_for_leaving_last_settled_home(record) household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["other_reason_for_leaving_last_settled_home"]) expect(record.errors["reasonother"])
.to include(match(expected_error)) .to include(match(expected_error))
end end
it "expects that other reason is not provided" do it "expects that other reason is not provided" do
record.reason = 18 record.reason = 18
record.other_reason_for_leaving_last_settled_home = nil record.reasonother = nil
household_validator.validate_reason_for_leaving_last_settled_home(record) household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["other_reason_for_leaving_last_settled_home"]).to be_empty expect(record.errors["reasonother"]).to be_empty
end end
end end

4
spec/requests/form_controller_spec.rb

@ -248,9 +248,7 @@ RSpec.describe FormController, type: :request do
"housingneeds_f" => "Other disability requirements", "housingneeds_f" => "Other disability requirements",
"housingneeds_g" => "No disability requirements", "housingneeds_g" => "No disability requirements",
"divider_a" => true, "divider_a" => true,
"housingneeds_h" => "Don’t know", "housingneeds_h" => "Don’t know" },
"divider_b" => true,
"accessibility_requirements_prefer_not_to_say" => "Prefer not to say" },
}, nil }, nil
), ),
Form::Question.new("tenant_code", { "type" => "text" }, nil), Form::Question.new("tenant_code", { "type" => "text" }, nil),

Loading…
Cancel
Save