Browse Source

Move previous_la into conditional question for la_known, add a hing and reset la if la_known is not Yes"

pull/323/head
Kat 3 years ago
parent
commit
fd733905a0
  1. 8
      app/models/case_log.rb
  2. 25
      config/forms/2021_2022.json
  3. 16
      spec/models/case_log_spec.rb

8
app/models/case_log.rb

@ -309,15 +309,15 @@ private
end
def reset_location_fields!
reset_location(is_la_inferred, "la", "is_la_inferred", "property_postcode", "postcode", "postcod2")
reset_location(is_la_inferred, "la", "is_la_inferred", "property_postcode", "postcode", "postcod2", self.la_known)
end
def reset_previous_location_fields!
reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "previous_postcode", "ppostc1", "ppostc2")
reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "previous_postcode", "ppostc1", "ppostc2", self.previous_la_known)
end
def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, incode_key, outcode_key)
if is_inferred
def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, incode_key, outcode_key, is_la_known)
if is_inferred || is_la_known != "Yes"
self[la_key] = nil
end
self[is_inferred_key] = false

25
config/forms/2021_2022.json

@ -2486,7 +2486,7 @@
}
}
},
"previous_la_known": {
"previous_la": {
"header": "",
"description": "",
"questions": {
@ -2495,22 +2495,19 @@
"header": "Do you know the local authority of the household’s last settled accommodation?",
"hint_text": "This is also known as the household’s ’last settled home’.",
"type": "radio",
"hidden_in_check_answers": true,
"answer_options": {
"1": { "value": "Yes" },
"0": { "value": "No" }
},
"conditional_for": {
"prevloc": ["Yes"]
}
}
},
"depends_on": [{ "is_previous_la_inferred": false }]
},
"previous_la": {
"header": "",
"description": "",
"questions": {
},
"prevloc": {
"check_answer_label": "Location of household’s last settled accommodation",
"header": "Which local authority area did the household live in immediately before this letting?",
"hint_text": "Includes temporary accommodation.",
"hint_text": "Select ‘Northern Ireland’, ‘Scotland’, ‘Wales’ or ‘Outside the UK’ if the household’s last settled home was outside England.",
"type": "select",
"answer_options": {
"": "Select an option",
@ -2897,12 +2894,14 @@
"S92000003": "Scotland",
"W92000004": "Wales",
"9300000XX": "Outside UK"
},
"inferred_check_answers_value": {
"condition": { "previous_la_known": "No" },
"value": "Not known"
}
}
},
"depends_on": [
{ "previous_la_known": "Yes", "is_previous_la_inferred": false }
]
"depends_on": [{ "is_previous_la_inferred": false }]
},
"reasonable_preference": {
"header": "",

16
spec/models/case_log_spec.rb

@ -339,7 +339,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: "No" })
address_case_log.update!({ la: "Westminster" })
address_case_log.update!({ la_known: "Yes", la: "Westminster" })
record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["property_postcode"]).to eq(nil)
@ -395,9 +395,21 @@ RSpec.describe CaseLog do
expect(record_from_db["prevloc"]).to eq(nil)
end
it "correctly resets la if la is not known" do
address_case_log.update!({ previous_la_known: "Yes", previous_la: "Scotland" })
record_from_db = ActiveRecord::Base.connection.execute("select previous_la from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["previous_la"]).to eq(nil)
expect(address_case_log.previous_la).to eq("Scotland")
address_case_log.update!({ previous_la_known: "No" })
record_from_db = ActiveRecord::Base.connection.execute("select previous_la from case_logs where id=#{address_case_log.id}").to_a[0]
expect(address_case_log.previous_la).to eq(nil)
expect(record_from_db["previous_la"]).to eq(nil)
end
it "changes the prevloc if previous postcode changes from not known to known and provided" do
address_case_log.update!({ previous_postcode_known: "No" })
address_case_log.update!({ prevloc: "Westminster" })
address_case_log.update!({ previous_la_known: "Yes", prevloc: "Westminster" })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["previous_postcode"]).to eq(nil)

Loading…
Cancel
Save