Browse Source

CLDC-667 newprop derived variable (#426)

* Update keys of rsnvac for first lets

Making it match with what is in the data dictionary. It was a wuick enough
fix to be included in this branch since it pairs well with the newprop derived
variable implementation

* add newprop derived variable and tests

* fixes

* use ternary statement for newprop derivation
pull/429/head
Dushan 3 years ago committed by GitHub
parent
commit
b72eb9f3fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/models/case_log.rb
  2. 2
      app/models/validations/date_validations.rb
  3. 20
      config/forms/2021_2022.json
  4. 7
      db/migrate/20220325114252_add_newprop_derived_variable.rb
  5. 1
      db/schema.rb
  6. 1
      spec/fixtures/exports/case_logs.xml
  7. 32
      spec/models/case_log_spec.rb
  8. 6
      spec/models/validations/date_validations_spec.rb
  9. 18
      spec/models/validations/property_validations_spec.rb

5
app/models/case_log.rb

@ -185,7 +185,7 @@ class CaseLog < ApplicationRecord
end end
def has_first_let_vacancy_reason? def has_first_let_vacancy_reason?
[11, 12, 13].include?(rsnvac) [15, 16, 17].include?(rsnvac)
end end
def previous_tenancy_was_temporary? def previous_tenancy_was_temporary?
@ -351,6 +351,9 @@ private
self.vmonth = property_void_date.month self.vmonth = property_void_date.month
self.vyear = property_void_date.year self.vyear = property_void_date.year
end end
if rsnvac.present?
self.newprop = has_first_let_vacancy_reason? ? 1 : 2
end
self.incref = 1 if net_income_refused? self.incref = 1 if net_income_refused?
self.other_hhmemb = hhmemb - 1 if hhmemb.present? self.other_hhmemb = hhmemb - 1 if hhmemb.present?
self.renttype = RENT_TYPE_MAPPING[rent_type] self.renttype = RENT_TYPE_MAPPING[rent_type]

2
app/models/validations/date_validations.rb

@ -60,6 +60,6 @@ private
end end
def is_rsnvac_first_let?(record) def is_rsnvac_first_let?(record)
[11, 12, 13].include?(record["rsnvac"]) [15, 16, 17].include?(record["rsnvac"])
end end
end end

20
config/forms/2021_2022.json

@ -710,14 +710,14 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"12": { "15": {
"value": "First let of new-build property"
},
"16": {
"value": "First let of conversion, rehabilitation or acquired property" "value": "First let of conversion, rehabilitation or acquired property"
}, },
"13": { "17": {
"value": "First let of leased property" "value": "First let of leased property"
},
"11": {
"value": "First let of new-build property"
} }
} }
} }
@ -886,11 +886,11 @@
"depends_on": [ "depends_on": [
{ {
"renewal": 0, "renewal": 0,
"rsnvac": 12 "rsnvac": 16
}, },
{ {
"renewal": 0, "renewal": 0,
"rsnvac": 13 "rsnvac": 17
} }
] ]
}, },
@ -908,7 +908,7 @@
"depends_on": [ "depends_on": [
{ {
"renewal": 0, "renewal": 0,
"rsnvac": 11 "rsnvac": 15
} }
] ]
}, },
@ -945,11 +945,11 @@
"depends_on": [ "depends_on": [
{ {
"renewal": 0, "renewal": 0,
"rsnvac": 12 "rsnvac": 16
}, },
{ {
"renewal": 0, "renewal": 0,
"rsnvac": 13 "rsnvac": 17
} }
] ]
} }

7
db/migrate/20220325114252_add_newprop_derived_variable.rb

@ -0,0 +1,7 @@
class AddNewpropDerivedVariable < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :newprop, :integer
end
end
end

1
db/schema.rb

@ -223,6 +223,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.integer "vmonth" t.integer "vmonth"
t.integer "vyear" t.integer "vyear"
t.decimal "wchchrg", precision: 10, scale: 2 t.decimal "wchchrg", precision: 10, scale: 2
t.integer "newprop"
t.string "relat2" t.string "relat2"
t.string "relat3" t.string "relat3"
t.string "relat4" t.string "relat4"

1
spec/fixtures/exports/case_logs.xml vendored

@ -165,6 +165,7 @@
<vmonth>11</vmonth> <vmonth>11</vmonth>
<vyear>2019</vyear> <vyear>2019</vyear>
<wchchrg/> <wchchrg/>
<newprop>2</newprop>
<relat2>P</relat2> <relat2>P</relat2>
<relat3/> <relat3/>
<relat4/> <relat4/>

32
spec/models/case_log_spec.rb

@ -1577,6 +1577,38 @@ RSpec.describe CaseLog do
end end
end end
end end
context "when the data provider is filling in the reason for the property being vacant" do
let!(:first_let_case_log) do
described_class.create({
managing_organisation: organisation,
owning_organisation: organisation,
first_time_property_let_as_social_housing: 1,
})
end
let!(:relet_case_log) do
described_class.create({
managing_organisation: organisation,
owning_organisation: organisation,
first_time_property_let_as_social_housing: 0,
})
end
it "the newprop variable is correctly derived and saved as 1 for a first let vacancy reason" do
first_let_case_log.update!({ rsnvac: 15 })
record_from_db = ActiveRecord::Base.connection.execute("select newprop from case_logs where id=#{first_let_case_log.id}").to_a[0]
expect(record_from_db["newprop"]).to eq(1)
expect(first_let_case_log["newprop"]).to eq(1)
end
it "the newprop variable is correctly derived and saved as 2 for anything that is not a first let vacancy reason" do
relet_case_log.update!({ rsnvac: 2 })
record_from_db = ActiveRecord::Base.connection.execute("select newprop from case_logs where id=#{relet_case_log.id}").to_a[0]
expect(record_from_db["newprop"]).to eq(2)
expect(relet_case_log["newprop"]).to eq(2)
end
end
end end
describe "resetting invalidated fields" do describe "resetting invalidated fields" do

6
spec/models/validations/date_validations_spec.rb

@ -65,7 +65,7 @@ RSpec.describe Validations::DateValidations do
context "when reason for vacancy is first let of property" do context "when reason for vacancy is first let of property" do
it "validates that no major repair date is provided for a new build" do it "validates that no major repair date is provided for a new build" do
record.rsnvac = 11 record.rsnvac = 15
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
@ -73,7 +73,7 @@ RSpec.describe Validations::DateValidations do
end end
it "validates that no major repair date is provided for a conversion" do it "validates that no major repair date is provided for a conversion" do
record.rsnvac = 12 record.rsnvac = 16
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
@ -81,7 +81,7 @@ RSpec.describe Validations::DateValidations do
end end
it "validates that no major repair date is provided for a leased property" do it "validates that no major repair date is provided for a leased property" do
record.rsnvac = 13 record.rsnvac = 17
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])

18
spec/models/validations/property_validations_spec.rb

@ -235,13 +235,13 @@ RSpec.describe Validations::PropertyValidations do
it "expects to have a first let reason for vacancy" do it "expects to have a first let reason for vacancy" do
record.first_time_property_let_as_social_housing = 1 record.first_time_property_let_as_social_housing = 1
record.rsnvac = 11 record.rsnvac = 15
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty expect(record.errors["rsnvac"]).to be_empty
record.rsnvac = 12 record.rsnvac = 16
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty expect(record.errors["rsnvac"]).to be_empty
record.rsnvac = 13 record.rsnvac = 17
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty expect(record.errors["rsnvac"]).to be_empty
end end
@ -250,15 +250,15 @@ RSpec.describe Validations::PropertyValidations do
context "when the property has been let as social housing before" do context "when the property has been let as social housing before" do
it "validates that the reason for vacancy is not a first let as social housing reason" do it "validates that the reason for vacancy is not a first let as social housing reason" do
record.first_time_property_let_as_social_housing = 0 record.first_time_property_let_as_social_housing = 0
record.rsnvac = 11 record.rsnvac = 15
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]) expect(record.errors["rsnvac"])
.to include(match I18n.t("validations.property.rsnvac.first_let_not_social")) .to include(match I18n.t("validations.property.rsnvac.first_let_not_social"))
record.rsnvac = 12 record.rsnvac = 16
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]) expect(record.errors["rsnvac"])
.to include(match I18n.t("validations.property.rsnvac.first_let_not_social")) .to include(match I18n.t("validations.property.rsnvac.first_let_not_social"))
record.rsnvac = 13 record.rsnvac = 17
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]) expect(record.errors["rsnvac"])
.to include(match I18n.t("validations.property.rsnvac.first_let_not_social")) .to include(match I18n.t("validations.property.rsnvac.first_let_not_social"))
@ -266,13 +266,13 @@ RSpec.describe Validations::PropertyValidations do
it "expects the reason for vacancy to be a first let as social housing reason" do it "expects the reason for vacancy to be a first let as social housing reason" do
record.first_time_property_let_as_social_housing = 1 record.first_time_property_let_as_social_housing = 1
record.rsnvac = 11 record.rsnvac = 15
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty expect(record.errors["rsnvac"]).to be_empty
record.rsnvac = 12 record.rsnvac = 16
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty expect(record.errors["rsnvac"]).to be_empty
record.rsnvac = 13 record.rsnvac = 17
property_validator.validate_rsnvac(record) property_validator.validate_rsnvac(record)
expect(record.errors["rsnvac"]).to be_empty expect(record.errors["rsnvac"]).to be_empty
end end

Loading…
Cancel
Save