Browse Source

Cldc 657 full postcodes (#421)

* Rename full postcode columns

* Normalise the postcodes

* Fix test
pull/429/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
c43e730254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/admin/case_logs.rb
  2. 2
      app/admin/dashboard.rb
  3. 20
      app/models/case_log.rb
  4. 2
      app/models/form.rb
  5. 4
      app/models/validations/local_authority_validations.rb
  6. 8
      app/models/validations/property_validations.rb
  7. 8
      config/forms/2021_2022.json
  8. 6
      db/migrate/20220324152359_rename_postcode_columns.rb
  9. 4
      db/schema.rb
  10. 12
      docs/api/DLUHC-CORE-Data.v1.json
  11. 8
      spec/factories/case_log.rb
  12. 4
      spec/features/form/check_answers_page_spec.rb
  13. 4
      spec/features/form/conditional_questions_spec.rb
  14. 4
      spec/features/form/page_routing_spec.rb
  15. 2
      spec/features/form/saving_data_spec.rb
  16. 4
      spec/fixtures/complete_case_log.json
  17. 4
      spec/fixtures/exports/case_logs.xml
  18. 6
      spec/fixtures/forms/2021_2022.json
  19. 91
      spec/models/case_log_spec.rb
  20. 4
      spec/models/form/question_spec.rb
  21. 4
      spec/models/form_spec.rb
  22. 16
      spec/models/validations/local_authority_validations_spec.rb
  23. 6
      spec/models/validations/property_validations_spec.rb
  24. 16
      spec/requests/case_logs_controller_spec.rb

2
app/admin/case_logs.rb

@ -12,7 +12,7 @@ ActiveAdmin.register CaseLog do
column :updated_at
column :status
column :tenant_code
column :property_postcode
column :postcode_full
column :owning_organisation
column :managing_organisation
actions

2
app/admin/dashboard.rb

@ -11,7 +11,7 @@ ActiveAdmin.register_page "Dashboard" do
column :updated_at
column :status
column :tenant_code
column :property_postcode
column :postcode_full
end
end
end

20
app/models/case_log.rb

@ -22,8 +22,8 @@ class CaseLog < ApplicationRecord
has_paper_trail
validates_with CaseLogValidator
before_validation :process_postcode_changes!, if: :property_postcode_changed?
before_validation :process_previous_postcode_changes!, if: :previous_postcode_changed?
before_validation :process_postcode_changes!, if: :postcode_full_changed?
before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed?
before_validation :reset_invalidated_dependent_fields!
before_validation :reset_location_fields!, unless: :postcode_known?
before_validation :reset_previous_location_fields!, unless: :previous_postcode_known?
@ -332,9 +332,9 @@ private
end
def set_derived_fields!
if previous_postcode.present?
self.ppostc1 = UKPostcode.parse(previous_postcode).outcode
self.ppostc2 = UKPostcode.parse(previous_postcode).incode
if ppostcode_full.present?
self.ppostc1 = UKPostcode.parse(ppostcode_full).outcode
self.ppostc2 = UKPostcode.parse(ppostcode_full).incode
end
if mrcdate.present?
self.mrcday = mrcdate.day
@ -400,11 +400,13 @@ private
end
def process_postcode_changes!
process_postcode(property_postcode, "postcode_known", "is_la_inferred", "la", "postcode", "postcod2")
self.postcode_full = postcode_full.present? ? postcode_full.upcase.gsub(/\s+/, "") : postcode_full
process_postcode(postcode_full, "postcode_known", "is_la_inferred", "la", "postcode", "postcod2")
end
def process_previous_postcode_changes!
process_postcode(previous_postcode, "previous_postcode_known", "is_previous_la_inferred", "prevloc", "ppostc1", "ppostc2")
self.ppostcode_full = ppostcode_full.present? ? ppostcode_full.upcase.gsub(/\s+/, "") : ppostcode_full
process_postcode(ppostcode_full, "previous_postcode_known", "is_previous_la_inferred", "prevloc", "ppostc1", "ppostc2")
end
def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key, outcode_key, incode_key)
@ -419,11 +421,11 @@ private
end
def reset_location_fields!
reset_location(is_la_inferred, "la", "is_la_inferred", "property_postcode", "postcode", "postcod2", la_known)
reset_location(is_la_inferred, "la", "is_la_inferred", "postcode_full", "postcode", "postcod2", la_known)
end
def reset_previous_location_fields!
reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "previous_postcode", "ppostc1", "ppostc2", previous_la_known)
reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "ppostcode_full", "ppostc1", "ppostc2", previous_la_known)
end
def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, incode_key, outcode_key, is_la_known)

2
app/models/form.rb

@ -117,7 +117,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 previous_postcode_known prevloc property_postcode previous_postcode]
address_questions = %w[postcode_known la previous_postcode_known prevloc postcode_full ppostcode_full]
invalidated_pages(case_log).flat_map(&:questions).reject { |q| address_questions.include?(q.id) } || []
end

4
app/models/validations/local_authority_validations.rb

@ -2,10 +2,10 @@ module Validations::LocalAuthorityValidations
POSTCODE_REGEXP = Validations::PropertyValidations::POSTCODE_REGEXP
def validate_previous_accommodation_postcode(record)
postcode = record.previous_postcode
postcode = record.ppostcode_full
if record.previous_postcode_known? && (postcode.blank? || !postcode.match(POSTCODE_REGEXP))
error_message = I18n.t("validations.postcode")
record.errors.add :previous_postcode, error_message
record.errors.add :ppostcode_full, error_message
end
end
end

8
app/models/validations/property_validations.rb

@ -57,8 +57,8 @@ module Validations::PropertyValidations
def validate_la(record)
if record.la.present? && !LONDON_BOROUGHS.include?(record.la) && record.is_london_rent?
record.errors.add :la, I18n.t("validations.property.la.london_rent")
if record.postcode_known? && record.property_postcode.present?
record.errors.add :property_postcode, I18n.t("validations.property.la.london_rent_postcode")
if record.postcode_known? && record.postcode_full.present?
record.errors.add :postcode_full, I18n.t("validations.property.la.london_rent_postcode")
end
end
@ -94,10 +94,10 @@ module Validations::PropertyValidations
end
def validate_property_postcode(record)
postcode = record.property_postcode
postcode = record.postcode_full
if record.postcode_known? && (postcode.blank? || !postcode.match(POSTCODE_REGEXP))
error_message = I18n.t("validations.postcode")
record.errors.add :property_postcode, error_message
record.errors.add :postcode_full, error_message
end
end

8
config/forms/2021_2022.json

@ -196,13 +196,13 @@
}
},
"conditional_for": {
"property_postcode": [
"postcode_full": [
1
]
},
"hidden_in_check_answers": true
},
"property_postcode": {
"postcode_full": {
"check_answer_label": "Postcode",
"header": "What is the property’s postcode?",
"hint_text": "",
@ -3697,13 +3697,13 @@
}
},
"conditional_for": {
"previous_postcode": [
"ppostcode_full": [
1
]
},
"hidden_in_check_answers": true
},
"previous_postcode": {
"ppostcode_full": {
"check_answer_label": "Postcode of household’s last settled accommodation",
"header": "Postcode for the previous accommodation",
"hint_text": "",

6
db/migrate/20220324152359_rename_postcode_columns.rb

@ -0,0 +1,6 @@
class RenamePostcodeColumns < ActiveRecord::Migration[7.0]
def change
rename_column :case_logs, :previous_postcode, :ppostcode_full
rename_column :case_logs, :property_postcode, :postcode_full
end
end

4
db/schema.rb

@ -87,7 +87,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.integer "tenancylength"
t.integer "tenancy"
t.integer "landlord"
t.string "previous_postcode"
t.string "ppostcode_full"
t.integer "rsnvac"
t.integer "unittype_gn"
t.integer "beds"
@ -99,7 +99,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.integer "period"
t.integer "layear"
t.integer "lawaitlist"
t.string "property_postcode"
t.string "postcode_full"
t.integer "reasonpref"
t.integer "cbl"
t.integer "chr"

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

@ -324,7 +324,7 @@
"tenancy": 3,
"landlord": "This landlord",
"la": "Barnet",
"property_postcode": "NW1 5TY",
"postcode_full": "NW1 5TY",
"property_relet": 0,
"rsnvac": 0,
"property_reference": "P9876",
@ -354,7 +354,7 @@
"layear": 2,
"lawaitlist": 1,
"prevloc": "E07000105",
"previous_postcode": "SE2 6RT",
"ppostcode_full": "SE2 6RT",
"reasonpref": 1,
"cbl": 1,
"chr": 1,
@ -625,7 +625,7 @@
"type": "string",
"minLength": 1
},
"previous_postcode": {
"ppostcode_full": {
"type": "string",
"minLength": 1
},
@ -710,7 +710,7 @@
"type": "string",
"minLength": 1
},
"property_postcode": {
"postcode_full": {
"type": "string",
"minLength": 1
},
@ -866,7 +866,7 @@
"lettype",
"landlord",
"la",
"previous_postcode",
"ppostcode_full",
"property_relet",
"rsnvac",
"property_reference",
@ -892,7 +892,7 @@
"layear",
"lawaitlist",
"prevloc",
"property_postcode",
"postcode_full",
"reasonpref",
"reasonable_preference_reason",
"cbl",

8
spec/factories/case_log.rb

@ -12,8 +12,8 @@ FactoryBot.define do
trait :in_progress do
status { 1 }
tenant_code { "TH356" }
property_postcode { "PO5 3TE" }
previous_postcode { "SW2 6HI" }
postcode_full { "PO5 3TE" }
ppostcode_full { "SW2 6HI" }
age1 { 17 }
end
trait :soft_validations_triggered do
@ -58,7 +58,7 @@ FactoryBot.define do
tenancylength { 5 }
tenancy { 3 }
landlord { 1 }
previous_postcode { "SE2 6RT" }
ppostcode_full { "SE2 6RT" }
rsnvac { 7 }
unittype_gn { 2 }
beds { 3 }
@ -79,7 +79,7 @@ FactoryBot.define do
tcharge { 325 }
layear { 2 }
lawaitlist { 1 }
property_postcode { "NW1 5TY" }
postcode_full { "NW1 5TY" }
reasonpref { 1 }
cbl { 1 }
chr { 1 }

4
spec/features/form/check_answers_page_spec.rb

@ -184,9 +184,9 @@ RSpec.describe "Form Check Answers Page" do
age1: nil,
layear: 2,
lawaitlist: 1,
property_postcode: "NW1 5TY",
postcode_full: "NW1 5TY",
reason: 4,
previous_postcode: "SE2 6RT",
ppostcode_full: "SE2 6RT",
mrcdate: Time.zone.parse("03/11/2019"),
)
end

4
spec/features/form/conditional_questions_spec.rb

@ -38,9 +38,9 @@ RSpec.describe "Form Conditional Questions" do
context "when a conditional question has a saved answer", js: true do
it "is displayed correctly" do
case_log.update!(postcode_known: 1, property_postcode: "NW1 6RT")
case_log.update!(postcode_known: 1, postcode_full: "NW1 6RT")
visit("/logs/#{id}/property-postcode")
expect(page).to have_field("case-log-property-postcode-field", with: "NW1 6RT")
expect(page).to have_field("case-log-postcode-full-field", with: "NW16RT")
end
end
end

4
spec/features/form/page_routing_spec.rb

@ -50,7 +50,7 @@ RSpec.describe "Form Page Routing" do
context "when the answers are inferred", js: true do
it "shows question if the answer could not be inferred" do
visit("/logs/#{id}/property-postcode")
fill_in("case-log-property-postcode-field", with: "PO5 3TE")
fill_in("case-log-postcode-full-field", with: "PO5 3TE")
click_button("Save and continue")
expect(page).to have_current_path("/logs/#{id}/do-you-know-the-local-authority")
end
@ -66,7 +66,7 @@ RSpec.describe "Form Page Routing" do
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {})
visit("/logs/#{id}/property-postcode")
fill_in("case-log-property-postcode-field", with: "P0 5ST")
fill_in("case-log-postcode-full-field", with: "P0 5ST")
click_button("Save and continue")
expect(page).to have_current_path("/logs/#{id}/property-wheelchair-accessible")
end

2
spec/features/form/saving_data_spec.rb

@ -73,7 +73,7 @@ RSpec.describe "Form Saving Data" do
it "displays number answers in inputs if they are already saved" do
visit("/logs/#{id}/property-postcode")
expect(page).to have_field("case-log-property-postcode-field", with: "PO5 3TE")
expect(page).to have_field("case-log-postcode-full-field", with: "PO53TE")
end
it "displays text answers in inputs if they are already saved" do

4
spec/fixtures/complete_case_log.json vendored

@ -55,7 +55,7 @@
"tenancy": 3,
"landlord": "This landlord",
"la": "Barnet",
"property_postcode": "NW1 5TY",
"postcode_full": "NW1 5TY",
"property_relet": 0,
"rsnvac": 0,
"property_reference": "P9876",
@ -88,7 +88,7 @@
"layear": 2,
"lawaitlist": 1,
"prevloc": "E07000105",
"previous_postcode": "SE2 6RT",
"ppostcode_full": "SE2 6RT",
"reasonpref": 1,
"cbl": 1,
"chr": 1,

4
spec/fixtures/exports/case_logs.xml vendored

@ -45,7 +45,7 @@
<tenancylength>5</tenancylength>
<tenancy>3</tenancy>
<landlord>1</landlord>
<previous_postcode>SE2 6RT</previous_postcode>
<ppostcode_full>SE26RT</ppostcode_full>
<rsnvac>7</rsnvac>
<unittype_gn>2</unittype_gn>
<beds>3</beds>
@ -57,7 +57,7 @@
<period>2</period>
<layear>2</layear>
<lawaitlist>1</lawaitlist>
<property_postcode>NW1 5TY</property_postcode>
<postcode_full>NW15TY</postcode_full>
<reasonpref>1</reasonpref>
<cbl>1</cbl>
<chr>1</chr>

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

@ -379,13 +379,13 @@
}
},
"conditional_for": {
"property_postcode": [
"postcode_full": [
1
]
},
"hidden_in_check_answers": true
},
"property_postcode": {
"postcode_full": {
"check_answer_label": "Postcode",
"header": "",
"hint_text": "",
@ -888,7 +888,7 @@
"width": 5,
"conditional_for": { "fake_key": "fake_condition" }
},
"previous_postcode": {
"ppostcode_full": {
"check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation",
"header": "Postcode for the previous accommodation",
"hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed",

91
spec/models/case_log_spec.rb

@ -196,8 +196,8 @@ RSpec.describe CaseLog do
described_class.create({
managing_organisation: organisation,
owning_organisation: organisation,
property_postcode: "M1 1AE",
previous_postcode: "M2 2AE",
postcode_full: "M1 1AE",
ppostcode_full: "M2 2AE",
startdate: Time.gm(2021, 10, 10),
mrcdate: Time.gm(2021, 5, 4),
property_void_date: Time.gm(2021, 3, 3),
@ -1134,6 +1134,15 @@ RSpec.describe CaseLog do
end
end
def check_postcode_fields(postcode_field, outcode_field, incode_field)
record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field}, #{outcode_field}, #{incode_field} from case_logs where id=#{address_case_log.id}").to_a[0]
expect(address_case_log[postcode_field]).to eq("M11AE")
expect(record_from_db[postcode_field]).to eq("M11AE")
expect(address_case_log[outcode_field]).to eq("M1")
expect(record_from_db[outcode_field]).to eq("M1")
expect(address_case_log[incode_field]).to eq("1AE")
expect(record_from_db[incode_field]).to eq("1AE")
end
context "when saving addresses" do
before do
stub_request(:get, /api.postcodes.io/)
@ -1145,10 +1154,28 @@ RSpec.describe CaseLog do
managing_organisation: organisation,
owning_organisation: organisation,
postcode_known: 1,
property_postcode: "M1 1AE",
postcode_full: "M1 1AE",
})
end
def check_property_postcode_fields
check_postcode_fields("postcode_full", "postcode", "postcod2")
end
it "correctly formats previous postcode" do
address_case_log.update!(postcode_full: "M1 1AE")
check_property_postcode_fields
address_case_log.update!(postcode_full: "m1 1ae")
check_property_postcode_fields
address_case_log.update!(postcode_full: "m11Ae")
check_property_postcode_fields
address_case_log.update!(postcode_full: "m11ae")
check_property_postcode_fields
end
it "correctly infers la" do
record_from_db = ActiveRecord::Base.connection.execute("select la from case_logs where id=#{address_case_log.id}").to_a[0]
expect(address_case_log.la).to eq("E08000003")
@ -1156,12 +1183,12 @@ RSpec.describe CaseLog do
end
it "errors if the property postcode is emptied" do
expect { address_case_log.update!({ property_postcode: "" }) }
expect { address_case_log.update!({ postcode_full: "" }) }
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
it "errors if the property postcode is not valid" do
expect { address_case_log.update!({ property_postcode: "invalid_postcode" }) }
expect { address_case_log.update!({ postcode_full: "invalid_postcode" }) }
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
@ -1172,15 +1199,15 @@ RSpec.describe CaseLog do
it "logs a warning" do
expect(Rails.logger).to receive(:warn).with("Postcodes.io lookup timed out")
address_case_log.update!({ postcode_known: 1, property_postcode: "M1 1AD" })
address_case_log.update!({ postcode_known: 1, postcode_full: "M1 1AD" })
end
end
it "correctly resets all fields if property postcode not known" do
address_case_log.update!({ postcode_known: 0 })
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)
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)
expect(address_case_log.la).to eq(nil)
expect(record_from_db["la"]).to eq(nil)
end
@ -1189,15 +1216,15 @@ RSpec.describe CaseLog do
address_case_log.update!({ postcode_known: 0 })
address_case_log.update!({ la_known: 1, la: "E09000033" })
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)
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)
expect(address_case_log.la).to eq("E09000033")
expect(record_from_db["la"]).to eq("E09000033")
address_case_log.update!({ postcode_known: 1, property_postcode: "M1 1AD" })
address_case_log.update!({ postcode_known: 1, postcode_full: "M1 1AD" })
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("M1 1AD")
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("M11AD")
expect(address_case_log.la).to eq("E08000003")
expect(record_from_db["la"]).to eq("E08000003")
end
@ -1214,10 +1241,28 @@ RSpec.describe CaseLog do
managing_organisation: organisation,
owning_organisation: organisation,
previous_postcode_known: 1,
previous_postcode: "M1 1AE",
ppostcode_full: "M1 1AE",
})
end
def check_previous_postcode_fields
check_postcode_fields("ppostcode_full", "ppostc1", "ppostc2")
end
it "correctly formats previous postcode" do
address_case_log.update!(ppostcode_full: "M1 1AE")
check_previous_postcode_fields
address_case_log.update!(ppostcode_full: "m1 1ae")
check_previous_postcode_fields
address_case_log.update!(ppostcode_full: "m11Ae")
check_previous_postcode_fields
address_case_log.update!(ppostcode_full: "m11ae")
check_previous_postcode_fields
end
it "correctly infers prevloc" do
record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0]
expect(address_case_log.prevloc).to eq("E08000003")
@ -1225,20 +1270,20 @@ RSpec.describe CaseLog do
end
it "errors if the previous postcode is emptied" do
expect { address_case_log.update!({ previous_postcode: "" }) }
expect { address_case_log.update!({ ppostcode_full: "" }) }
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
it "errors if the previous postcode is not valid" do
expect { address_case_log.update!({ previous_postcode: "invalid_postcode" }) }
expect { address_case_log.update!({ ppostcode_full: "invalid_postcode" }) }
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
it "correctly resets all fields if previous postcode not known" do
address_case_log.update!({ previous_postcode_known: 0 })
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)
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(address_case_log.prevloc).to eq(nil)
expect(record_from_db["prevloc"]).to eq(nil)
end
@ -1260,15 +1305,15 @@ RSpec.describe CaseLog do
address_case_log.update!({ previous_postcode_known: 0 })
address_case_log.update!({ previous_la_known: 1, prevloc: "E09000033" })
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)
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(address_case_log.prevloc).to eq("E09000033")
expect(record_from_db["prevloc"]).to eq("E09000033")
address_case_log.update!({ previous_postcode_known: 0, previous_postcode: "M1 1AD" })
address_case_log.update!({ previous_postcode_known: 0, ppostcode_full: "M1 1AD" })
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("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]
expect(record_from_db["ppostcode_full"]).to eq("M11AD")
expect(address_case_log.prevloc).to eq("E08000003")
expect(record_from_db["prevloc"]).to eq("E08000003")
end

4
spec/models/form/question_spec.rb

@ -211,7 +211,7 @@ RSpec.describe Form::Question, type: :model do
let(:section_id) { "tenancy_and_property" }
let(:subsection_id) { "property_information" }
let(:page_id) { "property_postcode" }
let(:case_log) { FactoryBot.build(:case_log, :in_progress, postcode_known: 0, property_postcode: nil) }
let(:case_log) { FactoryBot.build(:case_log, :in_progress, postcode_known: 0, postcode_full: nil) }
let(:question_id) { "property_postcode" }
it "displays 'change' in the check answers link text" do
@ -299,7 +299,7 @@ RSpec.describe Form::Question, type: :model do
let(:section_id) { "tenancy_and_property" }
let(:subsection_id) { "property_information" }
let(:page_id) { "property_postcode" }
let(:question_id) { "property_postcode" }
let(:question_id) { "postcode_full" }
it "returns true" do
case_log["postcode_known"] = 0

4
spec/models/form_spec.rb

@ -79,9 +79,9 @@ RSpec.describe Form, type: :model do
def answer_local_authority(case_log)
case_log.layear = "1 year but under 2 years"
case_log.lawaitlist = "Less than 1 year"
case_log.property_postcode = "NW1 5TY"
case_log.postcode_full = "NW1 5TY"
case_log.reason = "Permanently decanted from another property owned by this landlord"
case_log.previous_postcode = "SE2 6RT"
case_log.ppostcode_full = "SE2 6RT"
case_log.mrcdate = Time.zone.parse("03/11/2019")
end

16
spec/models/validations/local_authority_validations_spec.rb

@ -7,32 +7,32 @@ RSpec.describe Validations::LocalAuthorityValidations do
let(:record) { FactoryBot.create(:case_log) }
describe "#validate_previous_accommodation_postcode" do
it "does not add an error if the record previous_postcode is missing" do
record.previous_postcode = nil
it "does not add an error if the record ppostcode_full is missing" do
record.ppostcode_full = nil
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty
end
it "does not add an error if the record previous_postcode is valid (uppercase space)" do
it "does not add an error if the record ppostcode_full is valid (uppercase space)" do
record.previous_postcode_known = 1
record.previous_postcode = "M1 1AE"
record.ppostcode_full = "M1 1AE"
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty
end
it "does not add an error if the record previous_postcode is valid (lowercase no space)" do
it "does not add an error if the record ppostcode_full is valid (lowercase no space)" do
record.previous_postcode_known = 1
record.previous_postcode = "m11ae"
record.ppostcode_full = "m11ae"
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty
end
it "does add an error when the postcode is invalid" do
record.previous_postcode_known = 1
record.previous_postcode = "invalid"
record.ppostcode_full = "invalid"
local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).not_to be_empty
expect(record.errors["previous_postcode"]).to include(match I18n.t("validations.postcode"))
expect(record.errors["ppostcode_full"]).to include(match I18n.t("validations.postcode"))
end
end
end

6
spec/models/validations/property_validations_spec.rb

@ -156,7 +156,7 @@ RSpec.describe Validations::PropertyValidations do
record.rent_type = 2
property_validator.validate_la(record)
expect(record.errors["la"]).to include(match(expected_error))
expect(record.errors["property_postcode"]).to be_empty
expect(record.errors["postcode_full"]).to be_empty
end
it "expects that the local authority is in London" do
@ -173,9 +173,9 @@ RSpec.describe Validations::PropertyValidations do
record.la = "E07000105"
record.rent_type = 2
record.postcode_known = 1
record.property_postcode = "BN18 7TR"
record.postcode_full = "BN18 7TR"
property_validator.validate_la(record)
expect(record.errors["property_postcode"]).to include(match(expected_error))
expect(record.errors["postcode_full"]).to include(match(expected_error))
end
end
end

16
spec/requests/case_logs_controller_spec.rb

@ -29,7 +29,7 @@ RSpec.describe CaseLogsController, type: :request do
let(:age1) { 35 }
let(:offered) { 12 }
let(:period) { 2 }
let(:property_postcode) { "SE11 6TY" }
let(:postcode_full) { "SE116TY" }
let(:in_progress) { "in_progress" }
let(:completed) { "completed" }
@ -40,7 +40,7 @@ RSpec.describe CaseLogsController, type: :request do
"managing_organisation_id": managing_organisation.id,
"tenant_code": tenant_code,
"age1": age1,
"property_postcode": property_postcode,
"postcode_full": postcode_full,
"offered": offered,
"period": period,
}
@ -63,7 +63,7 @@ RSpec.describe CaseLogsController, type: :request do
json_response = JSON.parse(response.body)
expect(json_response["tenant_code"]).to eq(tenant_code)
expect(json_response["age1"]).to eq(age1)
expect(json_response["property_postcode"]).to eq(property_postcode)
expect(json_response["postcode_full"]).to eq(postcode_full)
end
context "with invalid json parameters" do
@ -283,7 +283,7 @@ RSpec.describe CaseLogsController, type: :request do
la_known: 1,
is_la_inferred: true,
postcode_known: 1,
property_postcode: "PO5 3TE")
postcode_full: "PO5 3TE")
id = case_log.id
get "/logs/#{id}/property-information/check-answers"
expected_inferred_answer = "<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">Manchester</span>"
@ -309,7 +309,7 @@ RSpec.describe CaseLogsController, type: :request do
describe "PATCH" do
let(:case_log) do
FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", property_postcode: "M1 1AE")
FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", postcode_full: "M1 1AE")
end
let(:params) do
{ tenant_code: "New Value" }
@ -327,7 +327,7 @@ RSpec.describe CaseLogsController, type: :request do
it "updates the case log with the given fields and keeps original values where none are passed" do
case_log.reload
expect(case_log.tenant_code).to eq("New Value")
expect(case_log.property_postcode).to eq("M1 1AE")
expect(case_log.postcode_full).to eq("M11AE")
end
context "with an invalid case log id" do
@ -367,7 +367,7 @@ RSpec.describe CaseLogsController, type: :request do
# what actually happens to an ActiveRecord object and what we're doing here, but either is allowed.
describe "PUT" do
let(:case_log) do
FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", property_postcode: "SW1A 2AA")
FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", postcode_full: "SW1A 2AA")
end
let(:params) do
{ tenant_code: "New Value" }
@ -385,7 +385,7 @@ RSpec.describe CaseLogsController, type: :request do
it "updates the case log with the given fields and keeps original values where none are passed" do
case_log.reload
expect(case_log.tenant_code).to eq("New Value")
expect(case_log.property_postcode).to eq("SW1A 2AA")
expect(case_log.postcode_full).to eq("SW1A2AA")
end
context "with an invalid case log id" do

Loading…
Cancel
Save