Browse Source

CLDC-1304: Renaming refactor part 1

pull/650/head
Stéphane Meny 3 years ago
parent
commit
9091e1d840
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 2
      app/models/bulk_upload.rb
  2. 26
      app/models/case_log.rb
  3. 2
      app/models/derived_variables/case_log_variables.rb
  4. 15
      app/models/validations/financial_validations.rb
  5. 2
      app/services/imports/case_logs_import_service.rb
  6. 2
      app/views/case_logs/_log_list.html.erb
  7. 131
      config/forms/2021_2022.json
  8. 12
      config/forms/2022_2023.json
  9. 1
      db/migrate/20220613123730_add_export_fields.rb
  10. 1
      db/schema.rb
  11. 9
      spec/factories/case_log.rb
  12. 8
      spec/features/form/check_answers_page_spec.rb
  13. 2
      spec/fixtures/forms/2021_2022.json
  14. 2
      spec/fixtures/forms/2022_2023.json
  15. 28
      spec/models/case_log_spec.rb
  16. 6
      spec/models/form/subsection_spec.rb
  17. 2
      spec/models/form_spec.rb
  18. 10
      spec/requests/case_logs_controller_spec.rb

2
app/models/bulk_upload.rb

@ -62,7 +62,7 @@ class BulkUpload
# managementgroup: row[4], # managementgroup: row[4],
# schemecode: row[5], # schemecode: row[5],
# firstletting: row[6], # firstletting: row[6],
tenant_code: row[7], tenancycode: row[7],
startertenancy: row[8], startertenancy: row[8],
tenancy: row[9], tenancy: row[9],
tenancyother: row[10], tenancyother: row[10],

26
app/models/case_log.rb

@ -9,7 +9,6 @@ class CaseLogValidator < ActiveModel::Validator
include Validations::DateValidations include Validations::DateValidations
include Validations::LocalAuthorityValidations include Validations::LocalAuthorityValidations
include Validations::SubmissionValidations include Validations::SubmissionValidations
include DerivedVariables::CaseLogVariables
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_") }
@ -19,6 +18,7 @@ end
class CaseLog < ApplicationRecord class CaseLog < ApplicationRecord
include Validations::SoftValidations include Validations::SoftValidations
include DerivedVariables::CaseLogVariables
has_paper_trail has_paper_trail
@ -53,7 +53,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("tenant_code 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("postcode_full ILIKE ?", "%#{postcode_full.gsub(/\s+/, '')}%") }
scope :search_by, lambda { |param| scope :search_by, lambda { |param|
@ -64,8 +64,7 @@ class CaseLog < ApplicationRecord
} }
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenant_code propcode].freeze OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode].freeze
RENT_TYPE_MAPPING = { 0 => 1, 1 => 2, 2 => 2, 3 => 3, 4 => 3, 5 => 3 }.freeze
RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze
HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
@ -198,7 +197,7 @@ class CaseLog < ApplicationRecord
def previous_postcode_known? def previous_postcode_known?
# 1: Yes # 1: Yes
previous_postcode_known == 1 ppcodenk == 1
end end
def previous_la_known? def previous_la_known?
@ -332,6 +331,11 @@ class CaseLog < ApplicationRecord
hb == 1 hb == 1
end end
def benefits_unknown?
# 3: Don’t know
hb == 3
end
# Option 8 has been removed starting from 22/23 # Option 8 has been removed starting from 22/23
def receives_housing_benefit_and_universal_credit? def receives_housing_benefit_and_universal_credit?
# 8: Housing benefit and Universal Credit (without housing element) # 8: Housing benefit and Universal Credit (without housing element)
@ -348,6 +352,11 @@ class CaseLog < ApplicationRecord
hb == 9 hb == 9
end end
def tenant_refuses_to_say_benefits?
hb == 10
end
# Option 7 has been removed starting from 22/23
def receives_universal_credit_but_no_housing_benefit? def receives_universal_credit_but_no_housing_benefit?
# 7: Universal Credit (without housing element) # 7: Universal Credit (without housing element)
hb == 7 hb == 7
@ -366,11 +375,6 @@ class CaseLog < ApplicationRecord
end end
end end
def benefits_unknown?
# 3: Don’t know
hb == 3
end
def local_housing_referral? def local_housing_referral?
# 3: PRP lettings only - Nominated by local housing authority # 3: PRP lettings only - Nominated by local housing authority
referral == 3 referral == 3
@ -532,7 +536,7 @@ private
def process_previous_postcode_changes! def process_previous_postcode_changes!
self.ppostcode_full = upcase_and_remove_whitespace(ppostcode_full) self.ppostcode_full = upcase_and_remove_whitespace(ppostcode_full)
process_postcode(ppostcode_full, "previous_postcode_known", "is_previous_la_inferred", "prevloc") process_postcode(ppostcode_full, "ppcodenk", "is_previous_la_inferred", "prevloc")
end end
def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key) def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key)

2
app/models/derived_variables/case_log_variables.rb

@ -1,4 +1,6 @@
module DerivedVariables::CaseLogVariables module DerivedVariables::CaseLogVariables
RENT_TYPE_MAPPING = { 0 => 1, 1 => 2, 2 => 2, 3 => 3, 4 => 3, 5 => 3 }.freeze
def set_derived_fields! def set_derived_fields!
# TODO: Remove once we support supported housing logs # TODO: Remove once we support supported housing logs
self.needstype = 1 unless needstype self.needstype = 1 unless needstype

15
app/models/validations/financial_validations.rb

@ -51,10 +51,21 @@ module Validations::FinancialValidations
end end
def validate_tshortfall(record) def validate_tshortfall(record)
if record.has_hbrentshortfall? && return unless record.startdate
if record.collection_start_year <= 2021
cannot_have_outstanding_amount = record.has_hbrentshortfall? &&
(record.benefits_unknown? ||
record.receives_no_benefits? ||
record.receives_universal_credit_but_no_housing_benefit?)
else
cannot_have_outstanding_amount = record.has_hbrentshortfall? &&
(record.benefits_unknown? || (record.benefits_unknown? ||
record.receives_no_benefits? || record.receives_no_benefits? ||
record.receives_universal_credit_but_no_housing_benefit?) tenant_refuses_to_say_benefits?)
end
if cannot_have_outstanding_amount
record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits")
end end
end end

2
app/services/imports/case_logs_import_service.rb

@ -61,7 +61,7 @@ module Imports
attributes["joint"] = unsafe_string_as_integer(xml_doc, "joint") attributes["joint"] = unsafe_string_as_integer(xml_doc, "joint")
attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a") attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a")
attributes["tenancy"] = unsafe_string_as_integer(xml_doc, "Q2b") attributes["tenancy"] = unsafe_string_as_integer(xml_doc, "Q2b")
attributes["tenant_code"] = string_or_nil(xml_doc, "_2bTenCode") attributes["tenancycode"] = string_or_nil(xml_doc, "_2bTenCode")
attributes["tenancyother"] = string_or_nil(xml_doc, "Q2ba") attributes["tenancyother"] = string_or_nil(xml_doc, "Q2ba")
attributes["tenancylength"] = safe_string_as_integer(xml_doc, "_2cYears") attributes["tenancylength"] = safe_string_as_integer(xml_doc, "_2cYears")
attributes["needstype"] = needs_type(xml_doc) attributes["needstype"] = needs_type(xml_doc)

2
app/views/case_logs/_log_list.html.erb

@ -51,7 +51,7 @@
<% end %> <% end %>
<% end %> <% end %>
<% row.cell( <% row.cell(
text: log.tenant_code? ? log.tenant_code : "–", text: log.tenancycode ? log.tenancycode : "–",
classes: "app-!-font-tabular", classes: "app-!-font-tabular",
) %> ) %>
<% row.cell( <% row.cell(

131
config/forms/2021_2022.json

@ -106,7 +106,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"tenant_code": { "tenancycode": {
"check_answer_label": "Tenant code", "check_answer_label": "Tenant code",
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "This is how you usually refer to this tenancy on your own systems.", "hint_text": "This is how you usually refer to this tenancy on your own systems.",
@ -1110,7 +1110,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"shelteredaccom": { "sheltered": {
"check_answer_label": "Is this letting in sheltered accommodation?", "check_answer_label": "Is this letting in sheltered accommodation?",
"header": "Is this letting in sheltered accommodation?", "header": "Is this letting in sheltered accommodation?",
"hint_text": "", "hint_text": "",
@ -1290,7 +1290,14 @@
"age1": [0] "age1": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age1_known": 0 }, { "age1_known": 1 }] "depends_on": [
{
"age1_known": 0
},
{
"age1_known": 1
}
]
} }
}, },
"age1": { "age1": {
@ -1988,7 +1995,14 @@
"age2": [0] "age2": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age2_known": 0 }, { "age2_known": 1 }] "depends_on": [
{
"age2_known": 0
},
{
"age2_known": 1
}
]
} }
}, },
"age2": { "age2": {
@ -2276,7 +2290,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_2": 0, "details_known_2": 0,
"age2": { "operator": ">", "operand": 15 } "age2": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_2": 0, "details_known_2": 0,
@ -2469,7 +2486,14 @@
"age3": [0] "age3": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age3_known": 0 }, { "age3_known": 1 }] "depends_on": [
{
"age3_known": 0
},
{
"age3_known": 1
}
]
} }
}, },
"age3": { "age3": {
@ -2757,7 +2781,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_3": 0, "details_known_3": 0,
"age3": { "operator": ">", "operand": 15 } "age3": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_3": 0, "details_known_3": 0,
@ -2947,7 +2974,14 @@
"age4": [0] "age4": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age4_known": 0 }, { "age4_known": 1 }] "depends_on": [
{
"age4_known": 0
},
{
"age4_known": 1
}
]
} }
}, },
"age4": { "age4": {
@ -3235,7 +3269,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_4": 0, "details_known_4": 0,
"age4": { "operator": ">", "operand": 15 } "age4": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_4": 0, "details_known_4": 0,
@ -3422,7 +3459,14 @@
"age5": [0] "age5": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age5_known": 0 }, { "age5_known": 1 }] "depends_on": [
{
"age5_known": 0
},
{
"age5_known": 1
}
]
} }
}, },
"age5": { "age5": {
@ -3710,7 +3754,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_5": 0, "details_known_5": 0,
"age5": { "operator": ">", "operand": 15 } "age5": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_5": 0, "details_known_5": 0,
@ -3894,7 +3941,14 @@
"age6": [0] "age6": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age6_known": 0 }, { "age6_known": 1 }] "depends_on": [
{
"age6_known": 0
},
{
"age6_known": 1
}
]
} }
}, },
"age6": { "age6": {
@ -4182,7 +4236,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_6": 0, "details_known_6": 0,
"age6": { "operator": ">", "operand": 15 } "age6": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_6": 0, "details_known_6": 0,
@ -4363,7 +4420,14 @@
"age7": [0] "age7": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age7_known": 0 }, { "age7_known": 1 }] "depends_on": [
{
"age7_known": 0
},
{
"age7_known": 1
}
]
} }
}, },
"age7": { "age7": {
@ -4651,7 +4715,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_7": 0, "details_known_7": 0,
"age7": { "operator": ">", "operand": 15 } "age7": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_7": 0, "details_known_7": 0,
@ -4829,7 +4896,14 @@
"age8": [0] "age8": [0]
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "age8_known": 0 }, { "age8_known": 1 }] "depends_on": [
{
"age8_known": 0
},
{
"age8_known": 1
}
]
} }
}, },
"age8": { "age8": {
@ -5117,7 +5191,10 @@
"depends_on": [ "depends_on": [
{ {
"details_known_8": 0, "details_known_8": 0,
"age8": { "operator": ">", "operand": 15 } "age8": {
"operator": ">",
"operand": 15
}
}, },
{ {
"details_known_8": 0, "details_known_8": 0,
@ -5986,7 +6063,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"previous_postcode_known": { "ppcodenk": {
"header": "Do you know the postcode of the household’s last settled accommodation?", "header": "Do you know the postcode of the household’s last settled accommodation?",
"hint_text": "This is also known as the household’s ‘last settled home’.", "hint_text": "This is also known as the household’s ‘last settled home’.",
"type": "radio", "type": "radio",
@ -6003,8 +6080,12 @@
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [ "depends_on": [
{ "previous_postcode_known": 0 }, {
{ "previous_postcode_known": 1 } "ppcodenk": 0
},
{
"ppcodenk": 1
}
] ]
} }
}, },
@ -6021,7 +6102,7 @@
}, },
"inferred_check_answers_value": { "inferred_check_answers_value": {
"condition": { "condition": {
"previous_postcode_known": 0 "ppcodenk": 0
}, },
"value": "Not known" "value": "Not known"
} }
@ -6039,8 +6120,12 @@
"type": "radio", "type": "radio",
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [ "depends_on": [
{ "previous_la_known": 0 }, {
{ "previous_la_known": 1 } "previous_la_known": 0
},
{
"previous_la_known": 1
}
] ]
}, },
"answer_options": { "answer_options": {

12
config/forms/2022_2023.json

@ -106,7 +106,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"tenant_code": { "tenancycode": {
"check_answer_label": "Tenant code", "check_answer_label": "Tenant code",
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "This is how you usually refer to this tenancy on your own systems.", "hint_text": "This is how you usually refer to this tenancy on your own systems.",
@ -1145,7 +1145,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"shelteredaccom": { "sheltered": {
"check_answer_label": "Is this letting in sheltered accommodation?", "check_answer_label": "Is this letting in sheltered accommodation?",
"header": "Is this letting in sheltered accommodation?", "header": "Is this letting in sheltered accommodation?",
"hint_text": "", "hint_text": "",
@ -6022,7 +6022,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"previous_postcode_known": { "ppcodenk": {
"header": "Do you know the postcode of the household’s last settled accommodation?", "header": "Do you know the postcode of the household’s last settled accommodation?",
"hint_text": "This is also known as the household’s ‘last settled home’.", "hint_text": "This is also known as the household’s ‘last settled home’.",
"type": "radio", "type": "radio",
@ -6040,10 +6040,10 @@
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [ "depends_on": [
{ {
"previous_postcode_known": 0 "ppcodenk": 0
}, },
{ {
"previous_postcode_known": 1 "ppcodenk": 1
} }
] ]
} }
@ -6061,7 +6061,7 @@
}, },
"inferred_check_answers_value": { "inferred_check_answers_value": {
"condition": { "condition": {
"previous_postcode_known": 0 "ppcodenk": 0
}, },
"value": "Not known" "value": "Not known"
} }

1
db/migrate/20220613123730_add_export_fields.rb

@ -7,6 +7,7 @@ class AddExportFields < ActiveRecord::Migration[7.0]
t.rename :tenant_code, :tenancycode t.rename :tenant_code, :tenancycode
t.rename :previous_postcode_known, :ppcodenk t.rename :previous_postcode_known, :ppcodenk
t.rename :shelteredaccom, :sheltered t.rename :shelteredaccom, :sheltered
t.remove :tenancy_code
end end
end end
end end

1
db/schema.rb

@ -53,7 +53,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_13_123730) do
t.integer "reservist" t.integer "reservist"
t.integer "illness" t.integer "illness"
t.integer "preg_occ" t.integer "preg_occ"
t.string "tenancy_code"
t.integer "startertenancy" t.integer "startertenancy"
t.integer "tenancylength" t.integer "tenancylength"
t.integer "tenancy" t.integer "tenancy"

9
spec/factories/case_log.rb

@ -11,7 +11,7 @@ FactoryBot.define do
end end
trait :in_progress do trait :in_progress do
status { 1 } status { 1 }
tenant_code { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }
postcode_full { Faker::Address.postcode } postcode_full { Faker::Address.postcode }
ppostcode_full { Faker::Address.postcode } ppostcode_full { Faker::Address.postcode }
age1 { 17 } age1 { 17 }
@ -24,7 +24,7 @@ FactoryBot.define do
incfreq { 1 } incfreq { 1 }
end end
trait :conditional_section_complete do trait :conditional_section_complete do
tenant_code { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }
age1 { 34 } age1 { 34 }
sex1 { "M" } sex1 { "M" }
ethnic { 2 } ethnic { 2 }
@ -34,7 +34,7 @@ FactoryBot.define do
end end
trait :completed do trait :completed do
status { 2 } status { 2 }
tenant_code { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }
age1 { 35 } age1 { 35 }
sex1 { "F" } sex1 { "F" }
ethnic { 2 } ethnic { 2 }
@ -52,7 +52,6 @@ FactoryBot.define do
reservist { 0 } reservist { 0 }
illness { 1 } illness { 1 }
preg_occ { 2 } preg_occ { 2 }
tenancy_code { Faker::Name.initials(number: 10) }
startertenancy { 0 } startertenancy { 0 }
tenancylength { 5 } tenancylength { 5 }
tenancy { 1 } tenancy { 1 }
@ -129,7 +128,7 @@ FactoryBot.define do
unitletas { 2 } unitletas { 2 }
has_benefits { 1 } has_benefits { 1 }
is_carehome { 0 } is_carehome { 0 }
shelteredaccom { 0 } sheltered { 0 }
declaration { 1 } declaration { 1 }
end end
created_at { Time.utc(2022, 2, 8, 16, 52, 15) } created_at { Time.utc(2022, 2, 8, 16, 52, 15) }

8
spec/features/form/check_answers_page_spec.rb

@ -148,7 +148,7 @@ RSpec.describe "Form Check Answers Page" do
:in_progress, :in_progress,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
tenant_code: "123", tenancycode: "123",
age1: 35, age1: 35,
sex1: "M", sex1: "M",
hhmemb: 1, hhmemb: 1,
@ -161,7 +161,7 @@ RSpec.describe "Form Check Answers Page" do
:in_progress, :in_progress,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
tenant_code: "123", tenancycode: "123",
age1: 35, age1: 35,
sex1: "M", sex1: "M",
hhmemb: 1, hhmemb: 1,
@ -176,7 +176,7 @@ RSpec.describe "Form Check Answers Page" do
:in_progress, :in_progress,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
tenant_code: "123", tenancycode: "123",
age1: 35, age1: 35,
sex1: "M", sex1: "M",
hhmemb: 1, hhmemb: 1,
@ -194,7 +194,7 @@ RSpec.describe "Form Check Answers Page" do
:in_progress, :in_progress,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
tenant_code: nil, tenancycode: nil,
age1: nil, age1: nil,
layear: 2, layear: 2,
waityear: 1, waityear: 1,

2
spec/fixtures/forms/2021_2022.json vendored

@ -12,7 +12,7 @@
"pages": { "pages": {
"tenant_code": { "tenant_code": {
"questions": { "questions": {
"tenant_code": { "tenancycode": {
"check_answer_label": "Tenant code", "check_answer_label": "Tenant code",
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "This is how you usually refer to this tenancy on your own systems.", "hint_text": "This is how you usually refer to this tenancy on your own systems.",

2
spec/fixtures/forms/2022_2023.json vendored

@ -87,7 +87,7 @@
"pages": { "pages": {
"tenant_code": { "tenant_code": {
"questions": { "questions": {
"tenant_code": { "tenancycode": {
"check_answer_label": "Tenant code", "check_answer_label": "Tenant code",
"header": "Different question header text for this year - 2023", "header": "Different question header text for this year - 2023",
"type": "text", "type": "text",

28
spec/models/case_log_spec.rb

@ -1228,7 +1228,7 @@ RSpec.describe CaseLog do
managing_organisation: owning_organisation, managing_organisation: owning_organisation,
owning_organisation:, owning_organisation:,
created_by: created_by_user, created_by: created_by_user,
previous_postcode_known: 1, ppcodenk: 1,
ppostcode_full: "M1 1AE", ppostcode_full: "M1 1AE",
}) })
end end
@ -1268,7 +1268,7 @@ RSpec.describe CaseLog do
end end
it "correctly resets all fields if previous postcode not known" do it "correctly resets all fields if previous postcode not known" do
address_case_log.update!({ previous_postcode_known: 0 }) address_case_log.update!({ ppcodenk: 0 })
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(nil) expect(record_from_db["ppostcode_full"]).to eq(nil)
@ -1277,7 +1277,7 @@ RSpec.describe CaseLog do
end end
it "correctly resets la if la is not known" do it "correctly resets la if la is not known" do
address_case_log.update!({ previous_postcode_known: 0 }) address_case_log.update!({ ppcodenk: 0 })
address_case_log.update!({ previous_la_known: 1, prevloc: "S92000003" }) address_case_log.update!({ previous_la_known: 1, prevloc: "S92000003" })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["prevloc"]).to eq("S92000003") expect(record_from_db["prevloc"]).to eq("S92000003")
@ -1290,7 +1290,7 @@ RSpec.describe CaseLog do
end end
it "changes the prevloc if previous postcode changes from not known to known and provided" do it "changes the prevloc if previous postcode changes from not known to known and provided" do
address_case_log.update!({ previous_postcode_known: 0 }) address_case_log.update!({ ppcodenk: 0 })
address_case_log.update!({ previous_la_known: 1, prevloc: "E09000033" }) address_case_log.update!({ previous_la_known: 1, prevloc: "E09000033" })
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]
@ -1298,7 +1298,7 @@ RSpec.describe CaseLog do
expect(address_case_log.prevloc).to eq("E09000033") expect(address_case_log.prevloc).to eq("E09000033")
expect(record_from_db["prevloc"]).to eq("E09000033") expect(record_from_db["prevloc"]).to eq("E09000033")
address_case_log.update!({ previous_postcode_known: 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("M11AD")
@ -1393,8 +1393,8 @@ RSpec.describe CaseLog do
it "correctly derives and saves waityear" do it "correctly derives and saves waityear" do
record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["waityear"]).to eq(1) expect(record_from_db["waityear"]).to eq(2)
expect(case_log["waityear"]).to eq(1) expect(case_log["waityear"]).to eq(2)
end end
it "correctly derives and saves underoccupation_benefitcap if year is 2021" do it "correctly derives and saves underoccupation_benefitcap if year is 2021" do
@ -1693,10 +1693,10 @@ RSpec.describe CaseLog do
end end
context "when the question type does not have answer options" do context "when the question type does not have answer options" do
let(:case_log) { FactoryBot.create(:case_log, :in_progress, housingneeds_a: 1, tenant_code: "test") } let(:case_log) { FactoryBot.create(:case_log, :in_progress, housingneeds_a: 1, tenancycode: "test") }
it "clears the answer" do it "clears the answer" do
expect { case_log.update!(housingneeds_a: 0) }.to change(case_log, :tenant_code).from("test").to(nil) expect { case_log.update!(housingneeds_a: 0) }.to change(case_log, :tenancycode).from("test").to(nil)
end end
end end
@ -1750,8 +1750,8 @@ RSpec.describe CaseLog do
case_log.update!({ renewal: 1 }) case_log.update!({ renewal: 1 })
record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["waityear"]).to eq(1) expect(record_from_db["waityear"]).to eq(2)
expect(case_log["waityear"]).to eq(1) expect(case_log["waityear"]).to eq(2)
case_log.update!({ renewal: 0 }) case_log.update!({ renewal: 0 })
record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0]
@ -1884,13 +1884,13 @@ RSpec.describe CaseLog do
describe "#filter_by_tenant_code" do describe "#filter_by_tenant_code" do
it "allows searching by a Tenant Code" do it "allows searching by a Tenant Code" do
result = described_class.filter_by_tenant_code(case_log_to_search.tenant_code) result = described_class.filter_by_tenant_code(case_log_to_search.tenancycode)
expect(result.count).to eq(1) expect(result.count).to eq(1)
expect(result.first.id).to eq case_log_to_search.id expect(result.first.id).to eq case_log_to_search.id
end end
context "when tenant_code has lower case letters" do context "when tenant_code has lower case letters" do
let(:matching_tenant_code_lower_case) { case_log_to_search.tenant_code.downcase } let(:matching_tenant_code_lower_case) { case_log_to_search.tenancycode.downcase }
it "allows searching by a Tenant Code" do it "allows searching by a Tenant Code" do
result = described_class.filter_by_tenant_code(matching_tenant_code_lower_case) result = described_class.filter_by_tenant_code(matching_tenant_code_lower_case)
@ -1934,7 +1934,7 @@ RSpec.describe CaseLog do
end end
it "allows searching using tenancy code" do it "allows searching using tenancy code" do
result = described_class.search_by(case_log_to_search.tenant_code) result = described_class.search_by(case_log_to_search.tenancycode)
expect(result.count).to eq(1) expect(result.count).to eq(1)
expect(result.first.id).to eq case_log_to_search.id expect(result.first.id).to eq case_log_to_search.id
end end

6
spec/models/form/subsection_spec.rb

@ -25,12 +25,12 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has pages" do it "has pages" do
expected_pages = %w[tenant_code person_1_age person_1_gender person_1_working_situation household_number_of_members person_2_working_situation propcode] expected_pages = %w[teanncycode person_1_age person_1_gender person_1_working_situation household_number_of_members person_2_working_situation propcode]
expect(subsection.pages.map(&:id)).to eq(expected_pages) expect(subsection.pages.map(&:id)).to eq(expected_pages)
end end
it "has questions" do it "has questions" do
expected_questions = %w[tenant_code age1 sex1 ecstat1 hhmemb relat2 age2 sex2 ecstat2 propcode] expected_questions = %w[teanncycode age1 sex1 ecstat1 hhmemb relat2 age2 sex2 ecstat2 propcode]
expect(subsection.questions.map(&:id)).to eq(expected_questions) expect(subsection.questions.map(&:id)).to eq(expected_questions)
end end
@ -73,7 +73,7 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has question helpers for the number of applicable questions" do it "has question helpers for the number of applicable questions" do
expected_questions = %w[tenant_code age1 sex1 ecstat1 hhmemb ecstat2 propcode] expected_questions = %w[teanncycode age1 sex1 ecstat1 hhmemb ecstat2 propcode]
expect(subsection.applicable_questions(case_log).map(&:id)).to eq(expected_questions) expect(subsection.applicable_questions(case_log).map(&:id)).to eq(expected_questions)
expect(subsection.applicable_questions_count(case_log)).to eq(7) expect(subsection.applicable_questions_count(case_log)).to eq(7)
end end

2
spec/models/form_spec.rb

@ -126,7 +126,7 @@ RSpec.describe Form, type: :model do
end end
before do before do
case_log.tenant_code = "123" case_log.tenancycode = "123"
case_log.age1 = 35 case_log.age1 = 35
case_log.sex1 = "M" case_log.sex1 = "M"
case_log.ecstat1 = 0 case_log.ecstat1 = 0

10
spec/requests/case_logs_controller_spec.rb

@ -149,7 +149,7 @@ RSpec.describe CaseLogsController, type: :request do
:case_log, :case_log,
owning_organisation: organisation, owning_organisation: organisation,
managing_organisation: organisation, managing_organisation: organisation,
tenant_code: "LC783", tenancycode: "LC783",
) )
end end
let!(:unauthorized_case_log) do let!(:unauthorized_case_log) do
@ -157,7 +157,7 @@ RSpec.describe CaseLogsController, type: :request do
:case_log, :case_log,
owning_organisation: other_organisation, owning_organisation: other_organisation,
managing_organisation: other_organisation, managing_organisation: other_organisation,
tenant_code: "UA984", tenancycode: "UA984",
) )
end end
@ -795,7 +795,7 @@ RSpec.describe CaseLogsController, type: :request do
describe "PATCH" do describe "PATCH" do
let(:case_log) do let(:case_log) do
FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", postcode_full: "M1 1AE") FactoryBot.create(:case_log, :in_progress, tenancycode: "Old Value", postcode_full: "M1 1AE")
end end
let(:params) do let(:params) do
{ tenant_code: "New Value" } { tenant_code: "New Value" }
@ -853,10 +853,10 @@ RSpec.describe CaseLogsController, type: :request do
# what actually happens to an ActiveRecord object and what we're doing here, but either is allowed. # what actually happens to an ActiveRecord object and what we're doing here, but either is allowed.
describe "PUT" do describe "PUT" do
let(:case_log) do let(:case_log) do
FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", postcode_full: "SW1A 2AA") FactoryBot.create(:case_log, :in_progress, tenancycode: "Old Value", postcode_full: "SW1A 2AA")
end end
let(:params) do let(:params) do
{ tenant_code: "New Value" } { tenancycode: "New Value" }
end end
let(:id) { case_log.id } let(:id) { case_log.id }

Loading…
Cancel
Save