From c6407d7da81844efb22c295ab7f2041211a43893 Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Wed, 15 Dec 2021 09:20:46 +0000 Subject: [PATCH 1/3] validat unitletas --- app/models/validations/property_validations.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index e11632544..d520b6dae 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -13,4 +13,10 @@ module Validations::PropertyValidations record.errors.add :la, "Local authority has to be in London" end end + + def validate_unitletas(record) + if record.unitletas.present? && (record.rsnvac == "First let of newbuild property" || record.rsnvac == "First let of conversion/rehabilitation/acquired property" || record.rsnvac == "First let of leased property") + record.errors.add :unitletas, "Can not be completed if it is the first let of the property" + end + end end From 0be93745504e59a6b3099640dcd136899393a733 Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Wed, 15 Dec 2021 15:51:08 +0000 Subject: [PATCH 2/3] unitletas validation specs --- spec/features/form/validations_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/features/form/validations_spec.rb b/spec/features/form/validations_spec.rb index 4aa72e261..f4690fe4a 100644 --- a/spec/features/form/validations_spec.rb +++ b/spec/features/form/validations_spec.rb @@ -162,4 +162,20 @@ RSpec.describe "validations" do end end end + + describe "Property Validations" do + context "first let of property and reason for vacancy completed" do + let(:rsnvac){ "First let of newbuild property" } + let(:rsnvac1){ "First let of conversion/rehabilitation/acquired property" } + let(:rsnvac2){ "First let of leased property" } + let(:unitletas){ "Social rent basis" } + + it "throws a validation error", js: true do + expect{ case_log.update!(rsnvac: rsnvac, unitletas: unitletas) }.to raise_error(ActiveRecord::RecordInvalid) + expect{ case_log.update!(rsnvac: rsnvac1, unitletas: unitletas) }.to raise_error(ActiveRecord::RecordInvalid) + expect{ case_log.update!(rsnvac: rsnvac2, unitletas: unitletas) }.to raise_error(ActiveRecord::RecordInvalid) + + end + end + end end From d7680b0399cd141c52c79c51851077685046e30f Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Thu, 16 Dec 2021 09:30:09 +0000 Subject: [PATCH 3/3] rubocop updates --- spec/features/form/validations_spec.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/features/form/validations_spec.rb b/spec/features/form/validations_spec.rb index f4690fe4a..4a78c4cf5 100644 --- a/spec/features/form/validations_spec.rb +++ b/spec/features/form/validations_spec.rb @@ -165,16 +165,15 @@ RSpec.describe "validations" do describe "Property Validations" do context "first let of property and reason for vacancy completed" do - let(:rsnvac){ "First let of newbuild property" } - let(:rsnvac1){ "First let of conversion/rehabilitation/acquired property" } - let(:rsnvac2){ "First let of leased property" } - let(:unitletas){ "Social rent basis" } + let(:rsnvac) { "First let of newbuild property" } + let(:rsnvac1) { "First let of conversion/rehabilitation/acquired property" } + let(:rsnvac2) { "First let of leased property" } + let(:unitletas) { "Social rent basis" } it "throws a validation error", js: true do - expect{ case_log.update!(rsnvac: rsnvac, unitletas: unitletas) }.to raise_error(ActiveRecord::RecordInvalid) - expect{ case_log.update!(rsnvac: rsnvac1, unitletas: unitletas) }.to raise_error(ActiveRecord::RecordInvalid) - expect{ case_log.update!(rsnvac: rsnvac2, unitletas: unitletas) }.to raise_error(ActiveRecord::RecordInvalid) - + expect { case_log.update!(rsnvac: rsnvac, unitletas: unitletas) }.to raise_error(ActiveRecord::RecordInvalid) + expect { case_log.update!(rsnvac: rsnvac1, unitletas: unitletas) }.to raise_error(ActiveRecord::RecordInvalid) + expect { case_log.update!(rsnvac: rsnvac2, unitletas: unitletas) }.to raise_error(ActiveRecord::RecordInvalid) end end end