Browse Source

remove la_known (#505)

* remove la_known

* lint
pull/506/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
06adfbaf6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/models/case_log.rb
  2. 2
      app/models/form.rb
  3. 2
      app/models/form/question.rb
  4. 4
      app/models/validations/local_authority_validations.rb
  5. 1
      app/services/imports/case_logs_import_service.rb
  6. 33
      config/forms/2021_2022.json
  7. 1
      config/locales/en.yml
  8. 13
      db/migrate/20220425145228_remove_la_known.rb
  9. 3
      db/schema.rb
  10. 1
      spec/factories/case_log.rb
  11. 16
      spec/features/form/accessible_autocomplete_spec.rb
  12. 6
      spec/features/form/check_answers_page_spec.rb
  13. 1
      spec/fixtures/exports/case_logs.xml
  14. 33
      spec/fixtures/forms/2021_2022.json
  15. 2
      spec/models/case_log_spec.rb
  16. 2
      spec/models/form/question_spec.rb
  17. 8
      spec/models/form/subsection_spec.rb
  18. 2
      spec/models/form_handler_spec.rb
  19. 9
      spec/models/validations/local_authority_validations_spec.rb
  20. 4
      spec/requests/case_logs_controller_spec.rb

9
app/models/case_log.rb

@ -50,7 +50,7 @@ class CaseLog < ApplicationRecord
}
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing tenant_code propcode].freeze
OPTIONAL_FIELDS = %w[postcode_known previous_la_known first_time_property_let_as_social_housing tenant_code 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
HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze
@ -180,11 +180,6 @@ class CaseLog < ApplicationRecord
previous_postcode_known == 1
end
def la_known?
# 1: Yes
la_known == 1
end
def previous_la_known?
# 1: Yes
previous_la_known == 1
@ -495,7 +490,7 @@ private
end
def reset_location_fields!
reset_location(is_la_inferred, "la", "is_la_inferred", "postcode_full", la_known)
reset_location(is_la_inferred, "la", "is_la_inferred", "postcode_full", 1)
end
def reset_previous_location_fields!

2
app/models/form.rb

@ -119,7 +119,7 @@ class Form
def invalidated_page_questions(case_log)
# we're already treating address fields as a special case and reset their values upon saving a case_log
address_questions = %w[postcode_known la_known la previous_postcode_known previous_la_known prevloc postcode_full ppostcode_full]
address_questions = %w[postcode_known la previous_postcode_known previous_la_known prevloc postcode_full ppostcode_full]
invalidated_pages(case_log).flat_map(&:questions).reject { |q| address_questions.include?(q.id) } || []
end

2
app/models/form/question.rb

@ -238,7 +238,6 @@ private
renewal: [1],
postcode_known: [1],
previous_postcode_known: [1],
la_known: [1],
previous_la_known: [1],
first_time_property_let_as_social_housing: [1],
wchair: [1],
@ -263,7 +262,6 @@ private
renewal: [0],
postcode_known: [0],
previous_postcode_known: [0],
la_known: [0],
previous_la_known: [0],
first_time_property_let_as_social_housing: [0],
wchair: [0],

4
app/models/validations/local_authority_validations.rb

@ -10,10 +10,6 @@ module Validations::LocalAuthorityValidations
end
def validate_la(record)
if record.la_known? && record.la.blank?
record.errors.add :la, I18n.t("validations.property.la.la_known")
end
if record.owning_organisation && record.owning_organisation.local_authorities.present? &&
record.la && !record.owning_organisation.local_authorities.include?(record.la)
la_name = record.form.get_question("la", record).label_from_value(record.la)

1
app/services/imports/case_logs_import_service.rb

@ -149,7 +149,6 @@ module Imports
# Required for our form invalidated questions (not present in import)
attributes["previous_la_known"] = 1 # Defaulting to Yes (Required)
attributes["la_known"] = 1 # Defaulting to Yes (Required)
attributes["is_la_inferred"] = false # Always keep the given LA
attributes["first_time_property_let_as_social_housing"] = first_time_let(attributes["rsnvac"])
attributes["declaration"] = declaration(xml_doc)

33
config/forms/2021_2022.json

@ -191,34 +191,9 @@
"header": "",
"description": "",
"questions": {
"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": "",
"type": "radio",
"hidden_in_check_answers": {
"depends_on": [
{ "la_known": 0 },
{ "la_known": 1 }
]
},
"answer_options": {
"1": {
"value": "Yes"
},
"0": {
"value": "No"
}
},
"conditional_for": {
"la": [
1
]
}
},
"la": {
"check_answer_label": "Local Authority",
"header": "Select a local authority",
"header": "What is the local authority of the property?",
"hint_text": "",
"type": "select",
"answer_options": {
@ -539,12 +514,6 @@
"E07000128": "Wyre",
"E07000239": "Wyre Forest",
"E06000014": "York"
},
"inferred_check_answers_value": {
"condition": {
"la_known": 0
},
"value": "Not known"
}
}
},

1
config/locales/en.yml

@ -67,7 +67,6 @@ en:
offered:
relet_number: "Number of times the property has been re-let must be between 0 and 20"
la:
la_known: "Enter name of local authority"
la_invalid_for_org: "%{org_name} does not operate in %{la_name}"
postcode_invalid_for_org: "Postcode must be in an area covered by %{org_name}"
rsnvac:

13
db/migrate/20220425145228_remove_la_known.rb

@ -0,0 +1,13 @@
class RemoveLaKnown < ActiveRecord::Migration[7.0]
def up
change_table :case_logs, bulk: true do |t|
t.remove :la_known
end
end
def down
change_table :case_logs, bulk: true do |t|
t.column :la_known, :integer
end
end
end

3
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_04_25_143130) do
ActiveRecord::Schema[7.0].define(version: 2022_04_25_145228) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -155,7 +155,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_04_25_143130) do
t.integer "needstype"
t.integer "lettype"
t.integer "postcode_known"
t.integer "la_known"
t.boolean "is_la_inferred"
t.integer "totchild"
t.integer "totelder"

1
spec/factories/case_log.rb

@ -128,7 +128,6 @@ FactoryBot.define do
has_benefits { 1 }
is_carehome { 0 }
letting_in_sheltered_accommodation { 0 }
la_known { 1 }
declaration { 1 }
end
created_at { Time.utc(2022, 2, 8, 16, 52, 15) }

16
spec/features/form/accessible_autocomplete_spec.rb

@ -8,8 +8,8 @@ RSpec.describe "Accessible Automcomplete" do
FactoryBot.create(
:case_log,
:in_progress,
la_known: 1,
la: "E09000033",
previous_la_known: 1,
prevloc: "E09000033",
is_la_inferred: false,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
@ -22,13 +22,13 @@ RSpec.describe "Accessible Automcomplete" do
it "allows type ahead filtering", js: true do
visit("/logs/#{case_log.id}/accessible-select")
find("#case-log-la-field").click.native.send_keys("T", "h", "a", "n", :down, :enter)
expect(find("#case-log-la-field").value).to eq("Thanet")
find("#case-log-prevloc-field").click.native.send_keys("T", "h", "a", "n", :down, :enter)
expect(find("#case-log-prevloc-field").value).to eq("Thanet")
end
it "maintains enhancement state across back navigation", js: true do
visit("/logs/#{case_log.id}/accessible-select")
find("#case-log-la-field").click.native.send_keys("T", "h", "a", "n", :down, :enter)
find("#case-log-prevloc-field").click.native.send_keys("T", "h", "a", "n", :down, :enter)
click_button("Save and continue")
click_link(text: "Back")
expect(page).to have_selector("input", class: "autocomplete__input", count: 1)
@ -36,12 +36,12 @@ RSpec.describe "Accessible Automcomplete" do
it "has a disabled null option" do
visit("/logs/#{case_log.id}/accessible-select")
expect(page).to have_select("case-log-la-field", disabled_options: ["Select an option"])
expect(page).to have_select("case-log-prevloc-field", disabled_options: ["Select an option"])
end
it "has the correct option selected if one has been saved" do
case_log.update!(postcode_known: 0, la_known: 1, la: "E07000178")
case_log.update!(postcode_known: 0, previous_la_known: 1, prevloc: "E07000178")
visit("/logs/#{case_log.id}/accessible-select")
expect(page).to have_select("case-log-la-field", selected: %w[Oxford])
expect(page).to have_select("case-log-prevloc-field", selected: %w[Oxford])
end
end

6
spec/features/form/check_answers_page_spec.rb

@ -17,9 +17,9 @@ RSpec.describe "Form Check Answers Page" do
let(:empty_case_log) do
FactoryBot.create(
:case_log,
la_known: 1,
la: "E09000033",
is_la_inferred: false,
previous_la_known: 1,
prevloc: "E09000033",
is_previous_la_inferred: false,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
)

1
spec/fixtures/exports/case_logs.xml vendored

@ -113,7 +113,6 @@
<needstype>1</needstype>
<lettype>7</lettype>
<postcode_known>1</postcode_known>
<la_known>1</la_known>
<is_la_inferred>false</is_la_inferred>
<totchild>0</totchild>
<totelder>0</totelder>

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

@ -302,7 +302,7 @@
},
"accessible_select": {
"questions": {
"la": {
"prevloc": {
"header": "Select options",
"hint_text": "Type ahead to filter the options",
"type": "select",
@ -321,8 +321,8 @@
},
"depends_on": [
{
"la_known": 1,
"is_la_inferred": false
"previous_la_known": 1,
"is_previous_la_inferred": false
}
]
},
@ -369,6 +369,31 @@
"property_information": {
"label": "Property information",
"pages": {
"accessible_select_too": {
"questions": {
"la": {
"header": "Select options",
"hint_text": "Type ahead to filter the options",
"type": "select",
"check_answer_label": "Accessible Select",
"answer_options": {
"" : "Select an option",
"E07000223": "Adur",
"E09000023": "Lewisham",
"E08000003": "Manchester",
"E07000178": "Oxford",
"E07000114": "Thanet",
"E09000033": "Westminster",
"E06000014": "York"
}
}
},
"depends_on": [
{
"is_la_inferred": false
}
]
},
"property_postcode": {
"header": "",
"description": "",
@ -411,7 +436,7 @@
"header": "",
"description": "",
"questions": {
"la_known": {
"previous_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": "",

2
spec/models/case_log_spec.rb

@ -1195,7 +1195,7 @@ RSpec.describe CaseLog do
it "changes the LA if property postcode changes from not known to known and provided" do
address_case_log.update!({ postcode_known: 0 })
address_case_log.update!({ la_known: 1, la: "E09000033" })
address_case_log.update!({ la: "E09000033" })
record_from_db = ActiveRecord::Base.connection.execute("select la, postcode_full from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["postcode_full"]).to eq(nil)

2
spec/models/form/question_spec.rb

@ -151,7 +151,7 @@ RSpec.describe Form::Question, type: :model do
let(:section_id) { "household" }
let(:subsection_id) { "household_needs" }
let(:page_id) { "accessible_select" }
let(:question_id) { "la" }
let(:question_id) { "prevloc" }
it "can map value from label" do
expect(question.value_from_label("Manchester")).to eq("E08000003")

8
spec/models/form/subsection_spec.rb

@ -81,13 +81,13 @@ RSpec.describe Form::Subsection, type: :model do
it "has question helpers for the number of answered questions" do
subsection_definition = section_definition["subsections"]["household_needs"]
subsection = described_class.new("household_needs", subsection_definition, section)
expected_questions = %w[armedforces illness accessibility_requirements la condition_effects]
expected_questions = %w[armedforces illness accessibility_requirements prevloc condition_effects]
case_log.armedforces = 3
case_log.illness = 1
case_log.housingneeds_a = 1
case_log.la_known = 1
case_log.is_la_inferred = false
case_log.la = "E06000014"
case_log.previous_la_known = 1
case_log.is_previous_la_inferred = false
case_log.prevloc = "E06000014"
case_log.illness_type_1 = 1
expect(subsection.answered_questions(case_log).map(&:id)).to eq(expected_questions)
expect(subsection.answered_questions_count(case_log)).to eq(5)

2
spec/models/form_handler_spec.rb

@ -17,7 +17,7 @@ RSpec.describe FormHandler do
form_handler = described_class.instance
form = form_handler.get_form(test_form_name)
expect(form).to be_a(Form)
expect(form.pages.count).to eq(34)
expect(form.pages.count).to eq(35)
end
end

9
spec/models/validations/local_authority_validations_spec.rb

@ -37,15 +37,6 @@ RSpec.describe Validations::LocalAuthorityValidations do
end
describe "#validate_la" do
context "when previous la is known" do
it "la has to be provided" do
record.la_known = 1
local_auth_validator.validate_la(record)
expect(record.errors["la"])
.to include(match I18n.t("validations.property.la.la_known"))
end
end
context "when the organisation only operates in specific local authorities" do
let(:organisation) { FactoryBot.create(:organisation) }
let(:record) { FactoryBot.create(:case_log, owning_organisation: organisation) }

4
spec/requests/case_logs_controller_spec.rb

@ -494,12 +494,10 @@ RSpec.describe CaseLogsController, type: :request do
sign_in user
end
it "shows the inferred postcode" do
it "shows the inferred la" do
case_log = FactoryBot.create(:case_log,
owning_organisation: organisation,
managing_organisation: organisation,
la_known: 1,
is_la_inferred: true,
postcode_known: 1,
postcode_full: "PO5 3TE")
id = case_log.id

Loading…
Cancel
Save