Browse Source

Change reason type

pull/83/head
Kat 4 years ago
parent
commit
675aeb632d
  1. 2
      app/admin/case_logs.rb
  2. 39
      app/constants/db_enums.rb
  3. 3
      app/models/case_log.rb
  4. 4
      app/validations/household_validations.rb
  5. 2
      config/forms/2021_2022.json
  6. 11
      db/migrate/20211108134601_further_core_migrations.rb
  7. 13
      db/migrate/20211108134601_remaining_core_migrations.rb
  8. 13
      db/migrate/20211108143649_change_reason_type.rb
  9. 5
      db/schema.rb
  10. 8
      docs/api/DLUHC-CORE-Data.v1.json
  11. 2
      spec/fixtures/complete_case_log.json
  12. 6
      spec/models/case_log_spec.rb

2
app/admin/case_logs.rb

@ -2,7 +2,7 @@ ActiveAdmin.register CaseLog do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
permit_params do
permitted = %i[status tenant_code age1 sex1 tenant_ethnic_group tenant_nationality previous_housing_situation armed_forces ecstat1 hhmemb relat2 age2 sex2 ecstat2 relat3 age3 sex3 ecstat3 relat4 age4 sex4 ecstat4 relat5 age5 sex5 ecstat5 relat6 age6 sex6 ecstat6 relat7 age7 person_7_gender ecstat7 relat8 age8 sex8 ecstat8 homelessness reason_for_leaving_last_settled_home benefit_cap_spare_room_subsidy armed_forces_active armed_forces_injured armed_forces_partner medical_conditions pregnancy accessibility_requirements condition_effects tenancy_code tenancy_start_date starter_tenancy fixed_term_tenancy tenancy_type letting_type letting_provider property_location previous_postcode property_relet property_vacancy_reason property_reference property_unit_type property_building_type property_number_of_bedrooms property_void_date property_major_repairs property_major_repairs_date property_number_of_times_relet property_wheelchair_accessible net_income net_income_frequency net_income_uc_proportion housing_benefit rent_frequency basic_rent service_charge personal_service_charge support_charge total_charge outstanding_amount time_lived_in_la time_on_la_waiting_list previous_la property_postcode reasonable_preference reasonable_preference_reason cbl_letting chr_letting cap_letting outstanding_rent_or_charges other_reason_for_leaving_last_settled_home accessibility_requirements_fully_wheelchair_accessible_housing accessibility_requirements_wheelchair_access_to_essential_rooms accessibility_requirements_level_access_housing accessibility_requirements_other_disability_requirements accessibility_requirements_no_disability_requirements accessibility_requirements_do_not_know accessibility_requirements_prefer_not_to_say condition_effects_vision condition_effects_hearing condition_effects_mobility condition_effects_dexterity condition_effects_stamina condition_effects_learning condition_effects_memory condition_effects_mental_health condition_effects_social_or_behavioral condition_effects_other condition_effects_prefer_not_to_say reasonable_preference_reason_homeless reasonable_preference_reason_unsatisfactory_housing reasonable_preference_reason_medical_grounds reasonable_preference_reason_avoid_hardship reasonable_preference_reason_do_not_know other_tenancy_type override_net_income_validation net_income_known]
permitted = %i[status tenant_code age1 sex1 tenant_ethnic_group tenant_nationality previous_housing_situation armed_forces ecstat1 hhmemb relat2 age2 sex2 ecstat2 relat3 age3 sex3 ecstat3 relat4 age4 sex4 ecstat4 relat5 age5 sex5 ecstat5 relat6 age6 sex6 ecstat6 relat7 age7 person_7_gender ecstat7 relat8 age8 sex8 ecstat8 homelessness reason benefit_cap_spare_room_subsidy armed_forces_active armed_forces_injured armed_forces_partner medical_conditions pregnancy accessibility_requirements condition_effects tenancy_code tenancy_start_date starter_tenancy fixed_term_tenancy tenancy_type letting_type letting_provider property_location previous_postcode property_relet property_vacancy_reason property_reference property_unit_type property_building_type property_number_of_bedrooms property_void_date property_major_repairs property_major_repairs_date property_number_of_times_relet property_wheelchair_accessible net_income net_income_frequency net_income_uc_proportion housing_benefit rent_frequency basic_rent service_charge personal_service_charge support_charge total_charge outstanding_amount time_lived_in_la time_on_la_waiting_list previous_la property_postcode reasonable_preference reasonable_preference_reason cbl_letting chr_letting cap_letting outstanding_rent_or_charges other_reason accessibility_requirements_fully_wheelchair_accessible_housing accessibility_requirements_wheelchair_access_to_essential_rooms accessibility_requirements_level_access_housing accessibility_requirements_other_disability_requirements accessibility_requirements_no_disability_requirements accessibility_requirements_do_not_know accessibility_requirements_prefer_not_to_say condition_effects_vision condition_effects_hearing condition_effects_mobility condition_effects_dexterity condition_effects_stamina condition_effects_learning condition_effects_memory condition_effects_mental_health condition_effects_social_or_behavioral condition_effects_other condition_effects_prefer_not_to_say reasonable_preference_reason_homeless reasonable_preference_reason_unsatisfactory_housing reasonable_preference_reason_medical_grounds reasonable_preference_reason_avoid_hardship reasonable_preference_reason_do_not_know other_tenancy_type override_net_income_validation net_income_known]
permitted
end

39
app/constants/db_enums.rb

@ -249,4 +249,43 @@ module DbEnums
"Do not know" => 6,
}
end
def self.reason
{
"Permanently decanted from another property owned by this landlord" => 1,
"Left home country as a refugee" => 2,
"Loss of tied accommodation" => 4,
"Domestic abuse" => 7,
"(Non violent) relationship breakdown with partner" => 8,
"Asked to leave by family or friends" => 9,
"Racial harassment" => 10,
"Other problems with neighbours" => 11,
"Property unsuitable because of overcrowding" => 12,
"End of assured shorthold tenancy - no fault" => 40,
"End of assured shorthold tenancy - tenant's fault" => 41,
"End of fixed term tenancy - no fault" => 42,
"End of fixed term tenancy - tenant's fault" => 43,
"Repossession" => 34,
"Under occupation - offered incentive to downsize" => 29,
"Under occupation - no incentive" => 30,
"Property unsuitable because of ill health / disability" => 13,
"Property unsuitable because of poor condition" => 14,
"Couldn't afford fees attached to renewing the tenancy" => 35,
"Couldn't afford increase in rent" => 36,
"Couldn't afford rent or mortgage - welfare reforms" => 37,
"Couldn't afford rent or mortgage - employment" => 38,
"Couldn't afford rent or mortgage - other" => 39,
"To move nearer to family / friends / school" => 16,
"To move nearer to work" => 17,
"To move to accomodation with support" => 18,
"To move to independent accomodation" => 19,
"Hate crime" => 31,
"Death of household member in last settled accomodation" => 46,
"Discharged from prison" => 44,
"Discharged from long stay hospital or similar institution" => 45,
"Other" => 20,
"Do not know" => 28,
"Prefer not to say" => 100,
}
end
end

3
app/models/case_log.rb

@ -101,6 +101,7 @@ class CaseLog < ApplicationRecord
enum layear: DbEnums.latime, _suffix: true
enum lawaitlist: DbEnums.latime, _suffix: true
enum reasonpref: DbEnums.polar2, _suffix: true
enum reason: DbEnums.reason, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
@ -162,7 +163,7 @@ private
dynamically_not_required = []
if reason_for_leaving_last_settled_home != "Other"
if reason != "Other"
dynamically_not_required << "other_reason_for_leaving_last_settled_home"
end

4
app/validations/household_validations.rb

@ -16,11 +16,11 @@ module HouseholdValidations
end
def validate_other_reason_for_leaving_last_settled_home(record)
validate_other_field(record, "reason_for_leaving_last_settled_home", "other_reason_for_leaving_last_settled_home")
validate_other_field(record, "reason", "other_reason_for_leaving_last_settled_home")
end
def validate_reason_for_leaving_last_settled_home(record)
if record.reason_for_leaving_last_settled_home == "Do not know" && record.underoccupation_benefitcap != "Do not know"
if record.reason == "Do not know" && record.underoccupation_benefitcap != "Do not know"
record.errors.add :underoccupation_benefitcap, "must be do not know if tenant’s main reason for leaving is do not know"
end
end

2
config/forms/2021_2022.json

@ -787,7 +787,7 @@
"header": "Leaving their last settled home",
"description": "",
"questions": {
"reason_for_leaving_last_settled_home": {
"reason": {
"header": "What is the tenant’s main reason for leaving?",
"hint_text": "",
"type": "radio",

11
db/migrate/20211108134601_further_core_migrations.rb

@ -0,0 +1,11 @@
class FurtherCoreMigrations < ActiveRecord::Migration[6.1]
def up
remove_column :case_logs, :condition_effects_prefer_not_to_say
rename_column :case_logs, :reason_for_leaving_last_settled_home, :reason
end
def down
add_column :case_logs, :condition_effects_prefer_not_to_say, :integer
rename_column :case_logs, :reason, :reason_for_leaving_last_settled_home
end
end

13
db/migrate/20211108134601_remaining_core_migrations.rb

@ -1,13 +0,0 @@
class RemainingCoreMigrations < ActiveRecord::Migration[6.1]
def up
change_table :case_logs, bulk: true do |_t|
remove_column :case_logs, :condition_effects_prefer_not_to_say
end
end
def down
change_table :case_logs, bulk: true do |_t|
add_column :case_logs, :condition_effects_prefer_not_to_say, :integer
end
end
end

13
db/migrate/20211108143649_change_reason_type.rb

@ -0,0 +1,13 @@
class ChangeReasonType < ActiveRecord::Migration[6.1]
def up
change_table :case_logs, bulk: true do |t|
t.change :reason, "integer USING reason::integer"
end
end
def down
change_table :case_logs, bulk: true do |t|
t.change :reason, :string
end
end
end

5
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_11_08_134601) do
ActiveRecord::Schema.define(version: 2021_11_08_143649) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -57,7 +57,7 @@ ActiveRecord::Schema.define(version: 2021_11_08_134601) do
t.string "sex8"
t.integer "ecstat8"
t.integer "homeless"
t.string "reason_for_leaving_last_settled_home"
t.integer "reason"
t.integer "underoccupation_benefitcap"
t.integer "leftreg"
t.integer "reservist"
@ -145,6 +145,7 @@ ActiveRecord::Schema.define(version: 2021_11_08_134601) do
t.string "needs_type"
t.string "sale_completion_date"
t.string "purchaser_code"
t.integer "condition_effects_prefer_not_to_say"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
end

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

@ -293,7 +293,7 @@
"sex8": "Prefer not to say",
"ecstat8": "Child under 16",
"homeless": "No",
"reason_for_leaving_last_settled_home": "Other problems with neighbours",
"reason": "Other problems with neighbours",
"underoccupation_benefitcap": "No",
"leftreg": "No",
"reservist": "No",
@ -343,7 +343,7 @@
"chr": false,
"cap": false,
"outstanding_rent_or_charges": 25,
"other_reason_for_leaving_last_settled_home": "Other reason",
"other_reason": "Other reason",
"housingneeds_a": true,
"housingneeds_b": false,
"housingneeds_c": false,
@ -727,7 +727,7 @@
"type": "string",
"minLength": 1
},
"reason_for_leaving_last_settled_home": {
"reason": {
"type": "string",
"minLength": 1,
"enum": [
@ -1082,7 +1082,7 @@
"sex8",
"ecstat8",
"homeless",
"reason_for_leaving_last_settled_home",
"reason",
"underoccupation_benefitcap",
"leftreg",
"reservist",

2
spec/fixtures/complete_case_log.json vendored

@ -38,7 +38,7 @@
"sex8": "Prefer not to say",
"ecstat8": "Child under 16",
"homeless": "Yes - other homelessness",
"reason_for_leaving_last_settled_home": "Other problems with neighbours",
"reason": "Other problems with neighbours",
"underoccupation_benefitcap": "No",
"leftreg": "No - they left up to 5 years ago",
"reservist": "No",

6
spec/models/case_log_spec.rb

@ -60,7 +60,7 @@ RSpec.describe Form, type: :model do
context "reason for leaving last settled home validation" do
it "Reason for leaving must be don't know if reason for leaving settled home (Q9a) is don't know." do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Do not know",
CaseLog.create!(reason: "Do not know",
underoccupation_benefitcap: "Yes - benefit cap")
}.to raise_error(ActiveRecord::RecordInvalid)
end
@ -68,14 +68,14 @@ RSpec.describe Form, type: :model do
context "other reason for leaving last settled home validation" do
it "must be provided if main reason for leaving last settled home was given as other" do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Other",
CaseLog.create!(reason: "Other",
other_reason_for_leaving_last_settled_home: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must not be provided if the main reason for leaving settled home is not other" do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Repossession",
CaseLog.create!(reason: "Repossession",
other_reason_for_leaving_last_settled_home: "the other reason provided")
}.to raise_error(ActiveRecord::RecordInvalid)
end

Loading…
Cancel
Save