Browse Source

Merge branch 'main' into CLDC-764/PageTitlesErrorPrefix

pull/149/head
Matthew Phelan 3 years ago
parent
commit
e5bcb4d293
  1. 6
      app/models/case_log.rb
  2. 38
      app/models/constants/case_log.rb
  3. 2
      app/models/validations/household_validations.rb
  4. 7
      app/models/validations/property_validations.rb
  5. 98
      config/forms/2021_2022.json
  6. 8
      db/migrate/20211203144855_add_postcode_known.rb
  7. 4
      db/schema.rb
  8. 18
      spec/models/case_log_spec.rb

6
app/models/case_log.rb

@ -113,10 +113,12 @@ class CaseLog < ApplicationRecord
enum renttype: RENT_TYPE, _suffix: true
enum needstype: NEEDS_TYPE, _suffix: true
enum lettype: LET_TYPE, _suffix: true
enum postcode_known: POLAR, _suffix: true
enum la_known: POLAR, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype lettype].freeze
OPTIONAL_FIELDS = %w[do_you_know_the_postcode
do_you_know_the_local_authority
OPTIONAL_FIELDS = %w[postcode_known
la_known
first_time_property_let_as_social_housing].freeze
def self.editable_fields

38
app/models/constants/case_log.rb

@ -17,7 +17,7 @@ module Constants::CaseLog
BUILTYPE = {
"Purpose built" => 1,
"Conversion" => 2,
"Converted from previous residential or non-residential property" => 2,
}.freeze
ECSTAT = {
@ -169,7 +169,7 @@ module Constants::CaseLog
"First let of leased property" => 17,
"Tenant evicted due to arrears" => 10,
"Tenant evicted due to ASB or other reason" => 11,
"Tenant died (no succession)" => 5,
"Previous tenant passed away (no succession)" => 5,
"Tenant moved to other social housing provider" => 12,
"Tenant abandoned property" => 6,
"Tenant moved to private sector or other accommodation" => 8,
@ -699,4 +699,38 @@ module Constants::CaseLog
"London living rent" => "Intermediate Rent",
"Other intermediate rent product" => "Intermediate Rent",
}.freeze
LONDON_BOROUGHS = ["City of London",
"Barking & Dagenham",
"Barnet",
"Bexley",
"Brent",
"Bromley",
"Camden",
"Croydon",
"Ealing",
"Enfield",
"Greenwich",
"Hackney",
"Hammersmith & Fulham",
"Haringey",
"Harrow",
"Havering",
"Hillingdon",
"Hounslow",
"Islington",
"Kensington & Chelsea",
"Kingston-upon-Thames",
"Lambeth",
"Lewisham",
"Merton",
"Newham",
"Redbridge",
"Richmond-upon-Thames",
"Southwark",
"Sutton",
"Tower Hamlets",
"Waltham Forest",
"Wandsworth",
"Westminster"].freeze
end

2
app/models/validations/household_validations.rb

@ -84,7 +84,7 @@ module Validations::HouseholdValidations
record.errors.add :unittype_gn, "A shared house must have 1 to 7 bedrooms"
end
if record.unittype_gn.include?("Shared") && !record.beds.to_i.between?(1, 3)
if record.unittype_gn.include?("Shared") && !record.beds.to_i.between?(1, 3) && record.beds.present?
record.errors.add :unittype_gn, "A shared house with less than two tenants must have 1 to 3 bedrooms"
end
end

7
app/models/validations/property_validations.rb

@ -1,9 +1,16 @@
module Validations::PropertyValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well
include Constants::CaseLog
def validate_property_number_of_times_relet(record)
if record.offered && !/^[1-9]$|^0[1-9]$|^1[0-9]$|^20$/.match?(record.offered.to_s)
record.errors.add :offered, "Property number of times relet must be between 0 and 20"
end
end
def validate_la(record)
if record.la.present? && !LONDON_BOROUGHS.include?(record.la) && (record.rent_type == "London Affordable rent" || record.rent_type == "London living rent")
record.errors.add :la, "Local authority has to be in London"
end
end
end

98
config/forms/2021_2022.json

@ -1097,9 +1097,9 @@
"description": "",
"questions": {
"propcode": {
"check_answer_label": "What’s the property reference?",
"check_answer_label": "Property reference",
"header": "What’s the property reference?",
"hint_text": "",
"hint_text": "This is how you refer to the property in your own systems.",
"type": "text",
"width": 10
}
@ -1109,9 +1109,9 @@
"header": "",
"description": "",
"questions": {
"do_you_know_the_postcode": {
"postcode_known": {
"check_answer_label": "Do you know the property postcode?",
"header": "Do you know the postcode?",
"header": "Do you know the property’s postcode?",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -1123,7 +1123,7 @@
}
},
"postcode": {
"check_answer_label": "",
"check_answer_label": "Postcode",
"header": "",
"hint_text": "",
"type": "text",
@ -1135,7 +1135,7 @@
"header": "",
"description": "",
"questions": {
"do_you_know_the_local_authority": {
"la_known": {
"check_answer_label": "Do you know what local authority the property is located in?",
"header": "Do you know what local authority the property is located in?",
"hint_text": "",
@ -1473,7 +1473,7 @@
}
}
},
"depends_on": { "do_you_know_the_local_authority": "Yes" }
"depends_on": { "la_known": "Yes" }
},
"why_dont_you_know_la": {
"header": "",
@ -1486,15 +1486,15 @@
"type": "text"
}
},
"depends_on": { "do_you_know_the_local_authority": "No" }
"depends_on": { "la_known": "No" }
},
"first_time_property_let_as_social_housing": {
"header": "",
"description": "",
"questions": {
"first_time_property_let_as_social_housing": {
"check_answer_label": "Which type was the property most recently let as?",
"header": "Is this property a relet?",
"check_answer_label": "Is this the first time the property has been let as social housing?",
"header": "Is this the first time the property has been let as social housing?",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -1510,8 +1510,8 @@
"description": "",
"questions": {
"unitletas": {
"check_answer_label": "Type property most recently let as",
"header": "Which type was the property most recently let as?",
"check_answer_label": "Type of let",
"header": "What type was the property most recently let as?",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -1529,8 +1529,8 @@
"description": "",
"questions": {
"rsnvac": {
"check_answer_label": "What is the reason for the property vacancy?",
"header": "What is the reason for the property vacancy?",
"check_answer_label": "Reason for vacant property",
"header": "What is the reason for the property being vacant?",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -1556,7 +1556,7 @@
"questions": {
"rsnvac": {
"check_answer_label": "What is the reason for the property vacancy?",
"header": "What is the reason for the property vacancy?",
"header": "What is the reason for the property being vacant?",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -1573,9 +1573,9 @@
"description": "",
"questions": {
"offered": {
"check_answer_label": "How many times has this unit been previously offered since becoming available for relet since becoming available for relet (after the last tenancy ended)?",
"header": "How many times has this unit been previously offered since becoming available for relet since becoming available for relet (after the last tenancy ended)?",
"hint_text": "If the property is being let for the first time, enter 0",
"check_answer_label": "Number of times property has been offered since available for relet",
"header": "How many times has this unit been previously offered since becoming available for relet (after the last tenancy ended)?",
"hint_text": "This is after the last tenancy ended. If the property is being let for the first time, enter 0",
"type": "numeric",
"min": 0,
"max": 150,
@ -1605,8 +1605,8 @@
"description": "",
"questions": {
"unittype_gn": {
"check_answer_label": "Which type of unit is the property?",
"header": "Which type of unit is the property?",
"check_answer_label": "Type of unit",
"header": "What type of unit is the property?",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -1627,7 +1627,7 @@
"description": "",
"questions": {
"builtype": {
"check_answer_label": "Building type",
"check_answer_label": "Type of building",
"header": "Which type of building is the property?",
"hint_text": "",
"type": "radio",
@ -1643,7 +1643,7 @@
"description": "",
"questions": {
"wchair": {
"check_answer_label": "Is property built or adapted to wheelchair user standards?",
"check_answer_label": "Property built or adapted to wheelchair-user standards",
"header": "Is property built or adapted to wheelchair user standards?",
"hint_text": "",
"type": "radio",
@ -1659,8 +1659,8 @@
"description": "",
"questions": {
"beds": {
"check_answer_label": "How many bedrooms are there in the property?",
"header": "How many bedrooms are there in the property?",
"check_answer_label": "Number of bedrooms",
"header": "How many bedrooms does the property have?",
"hint_text": "If shared accommodation, enter number of bedrooms occupied by this household; a bed-sit has 1 bedroom",
"type": "numeric",
"min": 0,
@ -1674,8 +1674,8 @@
"header": "",
"description": "",
"questions": {
"beds": {
"check_answer_label": "void/renewal date",
"property_void_date": {
"check_answer_label": "Void or renewal date",
"header": "What is the void or renewal date?",
"hint_text": "",
"type": "date"
@ -1683,40 +1683,29 @@
},
"depends_on": { "rsnvac": "First let of newbuild property", "tenant_same_property_renewal": "No" }
},
"property_major_repairs": {
"new_build_handover_date": {
"header": "",
"description": "",
"questions": {
"majorrepairs": {
"check_answer_label": "Were major repairs carried out during the void period?",
"header": "Were any major repairs completed during the void period?",
"property_void_date": {
"check_answer_label": "New build handover date",
"header": "What is the new build handover date?",
"hint_text": "",
"type": "radio",
"answer_options": {
"0": "No",
"1": "Yes"
},
"conditional_for": {
"mrcdate": ["Yes"]
},
"depends_on": { "tenant_same_property_renewal": "No" }
},
"mrcdate": {
"check_answer_label": "What was the major repairs completion date?",
"header": "What was the major repairs completion date?",
"hint_text": "For example, 27 3 2007",
"type": "date"
}
},
"depends_on": { "rsnvac": "First let of newbuild property" }
"depends_on": {
"tenant_same_property_renewal": "No",
"rsnvac": ["First let of conversion, rehabilitation or acquired property?", "First let of leased property"]
}
},
"new_build_handover_date": {
"property_major_repairs": {
"header": "",
"description": "",
"questions": {
"majorrepairs": {
"check_answer_label": "Were major repairs carried out during the void period?",
"header": "Were any major repairs completed during the void period?",
"check_answer_label": "Major repairs carried out during void period",
"header": "Were any major repairs carried out during the void period?",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -1725,13 +1714,16 @@
},
"conditional_for": {
"mrcdate": ["Yes"]
},
"depends_on": {
"tenant_same_property_renewal": "No",
"rsnvac": ["First let of conversion, rehabilitation or acquired property?", "First let of leased property"]
}
},
"mrcdate": {
"check_answer_label": "Completion date of repairs",
"header": "When were the repairs completed?",
"hint_text": "For example, 27 3 2007",
"type": "date"
}
}
},
"depends_on": { "rsnvac": "First let of newbuild property", "tenant_same_property_renewal": "No"}
}
}
}

8
db/migrate/20211203144855_add_postcode_known.rb

@ -0,0 +1,8 @@
class AddPostcodeKnown < ActiveRecord::Migration[6.1]
def change
change_table :case_logs, bulk: true do |t|
t.column :postcode_known, :integer
t.column :la_known, :integer
end
end
end

4
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_12_02_124802) do
ActiveRecord::Schema.define(version: 2021_12_03_144855) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -169,6 +169,8 @@ ActiveRecord::Schema.define(version: 2021_12_02_124802) do
t.integer "renttype"
t.integer "needstype"
t.integer "lettype"
t.integer "postcode_known"
t.integer "la_known"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"

18
spec/models/case_log_spec.rb

@ -808,6 +808,24 @@ RSpec.describe Form, type: :model do
}.not_to raise_error
end
end
context "Validate local authority" do
it "Has to be london if rent type london affordable rent" do
expect {
CaseLog.create!(la: "Ashford",
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(la: "Westminster",
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.not_to raise_error
end
end
end
describe "status" do

Loading…
Cancel
Save