Browse Source

Merge pull request #171 from communitiesuk/CLCD-501/validate_unitletas

Clcd 501/validate unitletas
pull/172/head
Matthew J. Phelan 3 years ago committed by GitHub
parent
commit
83ad9457b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/models/validations/property_validations.rb
  2. 15
      spec/features/form/validations_spec.rb

6
app/models/validations/property_validations.rb

@ -13,4 +13,10 @@ module Validations::PropertyValidations
record.errors.add :la, "Local authority has to be in London" record.errors.add :la, "Local authority has to be in London"
end end
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 end

15
spec/features/form/validations_spec.rb

@ -162,4 +162,19 @@ RSpec.describe "validations" do
end end
end 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 end

Loading…
Cancel
Save