From 247fd97ea42972bf53061635b8f0f3b8f2261f2d Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:26:15 +0100 Subject: [PATCH] Rebase --- .../validations/setup_validations_spec.rb | 107 +++++++++--------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/spec/models/validations/setup_validations_spec.rb b/spec/models/validations/setup_validations_spec.rb index aebe2803d..f459d1083 100644 --- a/spec/models/validations/setup_validations_spec.rb +++ b/spec/models/validations/setup_validations_spec.rb @@ -511,6 +511,59 @@ RSpec.describe Validations::SetupValidations do expect(record.errors["scheme_id"]).to be_empty end end + + context "with a scheme with no locations active on the start date & no location set" do + let(:scheme) { create(:scheme) } + let(:location) { create(:location, scheme:) } + + before do + location_deactivation_period = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) + location_deactivation_period.save!(validate: false) + location.reload + end + + it "produces error when scheme does not have any active locations on the tenancy start date" do + record.startdate = Time.zone.local(2022, 7, 5) + record.scheme = scheme + setup_validator.validate_tenancy(record) + expect(record.errors["startdate"]).to include(match I18n.t("validations.setup.startdate.scheme.locations_inactive.startdate", name: scheme.service_name)) + end + + it "produces no error when scheme has active locations on the tenancy start date" do + record.startdate = Time.zone.local(2022, 6, 1) + record.scheme = scheme + setup_validator.validate_tenancy(record) + expect(record.errors["startdate"]).to be_empty + end + + end + + context "with a scheme with no locations active on the start date & location also set" do + let(:scheme) { create(:scheme) } + let(:location) { create(:location, scheme:) } + + before do + location_deactivation_period = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) + location_deactivation_period.save!(validate: false) + location.reload + end + + it "produces error when scheme does not have any active locations on the tenancy start date" do + record.startdate = Time.zone.local(2022, 7, 5) + record.scheme = scheme + record.location = location + setup_validator.validate_tenancy(record) + expect(record.errors["startdate"]).to include(match I18n.t("validations.setup.startdate.scheme.locations_inactive.startdate", name: scheme.service_name)) + end + + it "produces no error when scheme has active locations on the tenancy start date" do + record.startdate = Time.zone.local(2022, 6, 1) + record.scheme = scheme + record.location = location + setup_validator.validate_tenancy(record) + expect(record.errors["startdate"]).to be_empty + end + end end describe "#validate_location" do @@ -647,60 +700,6 @@ RSpec.describe Validations::SetupValidations do expect(record.errors["location_id"]).to be_empty end end - end - - describe "validate_tenancy" do - context "with a scheme with no locations active on the start date & no location set" do - let(:scheme) { create(:scheme) } - let(:location) { create(:location, scheme:) } - - before do - location_deactivation_period = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) - location_deactivation_period.save!(validate: false) - location.reload - end - - it "produces error when scheme does not have any active locations on the tenancy start date" do - record.startdate = Time.zone.local(2022, 7, 5) - record.scheme = scheme - setup_validator.validate_tenancy(record) - expect(record.errors["startdate"]).to include(match I18n.t("validations.setup.startdate.scheme.locations_inactive.startdate", name: scheme.service_name)) - end - - it "produces no error when scheme has active locations on the tenancy start date" do - record.startdate = Time.zone.local(2022, 6, 1) - record.scheme = scheme - setup_validator.validate_tenancy(record) - expect(record.errors["startdate"]).to be_empty - end - end - - context "with a scheme with no locations active on the start date & location also set" do - let(:scheme) { create(:scheme) } - let(:location) { create(:location, scheme:) } - - before do - location_deactivation_period = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) - location_deactivation_period.save!(validate: false) - location.reload - end - - it "produces error when scheme does not have any active locations on the tenancy start date" do - record.startdate = Time.zone.local(2022, 7, 5) - record.scheme = scheme - record.location = location - setup_validator.validate_tenancy(record) - expect(record.errors["startdate"]).to include(match I18n.t("validations.setup.startdate.scheme.locations_inactive.startdate", name: scheme.service_name)) - end - - it "produces no error when scheme has active locations on the tenancy start date" do - record.startdate = Time.zone.local(2022, 6, 1) - record.scheme = scheme - record.location = location - setup_validator.validate_tenancy(record) - expect(record.errors["startdate"]).to be_empty - end - end context "with the chosen location inactive on the start date" do let(:scheme) { create(:scheme) }