From 513b3990bae6677dab69fe9c54cdf84bd9d17108 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 2 Dec 2022 11:12:24 +0000 Subject: [PATCH] test: fix failing tests --- spec/features/schemes_spec.rb | 1 + spec/models/location_spec.rb | 40 +++++++++++++++++++--- spec/requests/locations_controller_spec.rb | 4 +-- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 0f9659c82..718f981fa 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -514,6 +514,7 @@ RSpec.describe "Schemes scheme Features" do it "displays information about the first created location" do expect(page).to have_content "AA1 1AA" + click_link "AA1 1AA" expect(page).to have_content "Some name" expect(page).to have_content "5" expect(page).to have_content "Self-contained house" diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 8c3b055bf..1e1756a21 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -20,7 +20,7 @@ RSpec.describe Location, type: :model do end end - describe "#validate_postcode" do + describe "#postcode" do let(:location) { FactoryBot.build(:location) } it "does not add an error if postcode is valid" do @@ -37,8 +37,28 @@ RSpec.describe Location, type: :model do 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')}") + location.valid?(:postcode) + expect(location.errors.count).to eq(1) + end + end + + describe "#local_authority" do + let(:location) { FactoryBot.build(:location) } + + it "does add an error when the local authority is invalid" do + location.location_admin_district = "Select an option" + location.valid?(:location_admin_district) + expect(location.errors.count).to eq(1) + end + end + + describe "#name" do + let(:location) { FactoryBot.build(:location) } + + it "does add an error when the name is invalid" do + location.name = nil + location.valid?(:name) + expect(location.errors.count).to eq(1) end end @@ -67,8 +87,18 @@ RSpec.describe Location, type: :model do 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')}") + location.valid?(:mobility_type) + expect(location.errors.count).to eq(1) + end + end + + describe "#availability" do + let(:location) { FactoryBot.build(:location) } + + it "does add an error when the availability is invalid" do + location.startdate = Time.zone.local(1, 1, 1) + location.valid?(:startdate) + expect(location.errors.count).to eq(1) end end diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 682c2776b..e66a56918 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1244,7 +1244,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } - let!(:location) { FactoryBot.create(:location, scheme:) } + let!(:location) { FactoryBot.create(:location, scheme:, startdate: Time.zone.local(2000, 1, 1)) } before do sign_in user @@ -1288,7 +1288,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :support) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } - let!(:location) { FactoryBot.create(:location, scheme:) } + let!(:location) { FactoryBot.create(:location, scheme:, startdate: Time.zone.local(2000, 1, 1)) } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false)