From e4e203fb73d1e97d30bfe862458157e12b464687 Mon Sep 17 00:00:00 2001 From: Sam Seed Date: Tue, 29 Nov 2022 16:25:17 +0000 Subject: [PATCH] test: add missing location validations for nil postcode & mobility type --- spec/models/location_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 5209dd9f1..11c826d28 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -34,6 +34,12 @@ RSpec.describe Location, type: :model do expect { location.save! } .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Postcode #{I18n.t('validations.postcode')}") end + + it "does add an error when the postcode is missing" do + location.postcode = nil + expect { location.save! } + .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Postcode #{I18n.t('validations.postcode')}") + end end describe "#units" do @@ -56,6 +62,16 @@ RSpec.describe Location, type: :model do end end + describe "#mobility_type" do + let(:location) { FactoryBot.build(:location) } + + it "does add an error when the mobility type is invalid" do + location.mobility_type = nil + expect { location.save! } + .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Mobility type #{I18n.t('activerecord.errors.models.location.attributes.mobility_type.blank')}") + end + end + describe "paper trail" do let(:location) { FactoryBot.create(:location) } let!(:name) { location.name }