From ea7b757b291435a54e064675b5cf8567ee8c6b06 Mon Sep 17 00:00:00 2001 From: Carolyn Date: Mon, 17 Mar 2025 12:32:01 +0000 Subject: [PATCH] use before do instead of let for unreferenced variables --- spec/models/location_deactivation_period_spec.rb | 14 ++++++++++---- spec/models/scheme_deactivation_period_spec.rb | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/spec/models/location_deactivation_period_spec.rb b/spec/models/location_deactivation_period_spec.rb index da3dfcfdf..709aec749 100644 --- a/spec/models/location_deactivation_period_spec.rb +++ b/spec/models/location_deactivation_period_spec.rb @@ -88,7 +88,10 @@ RSpec.describe LocationDeactivationPeriod do context "when there is an open deactivation period less than six months in the future" do # validate_reactivation let!(:location) { FactoryBot.build(:location, created_at: previous_collection_start_date - 2.years) } - let!(:existing_period) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.now + 5.months, location:) } + + before do + FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.now + 5.months, location:) + end context "when reactivation date is nil" do let(:record) { FactoryBot.build(:location_deactivation_period, deactivation_date: Time.zone.now, location:) } @@ -124,9 +127,12 @@ RSpec.describe LocationDeactivationPeriod do context "when there is not an open deactivation period within six months" do # validate_deactivation let!(:location) { FactoryBot.create(:location, created_at: previous_collection_start_date - 2.years) } - let!(:existing_period_1) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.now + 7.months, reactivation_date: Time.zone.now + 8.months, location:) } - let!(:existing_period_2) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.now + 1.month, reactivation_date: Time.zone.now + 2.months, location:) } - let!(:existing_period_3) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.now + 9.months, location:) } + + before do + FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.now + 7.months, reactivation_date: Time.zone.now + 8.months, location:) + FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.now + 1.month, reactivation_date: Time.zone.now + 2.months, location:) + FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.now + 9.months, location:) + end context "when reactivation date is nil" do let(:record) { FactoryBot.build(:location_deactivation_period, deactivation_date: Time.zone.now, location:) } diff --git a/spec/models/scheme_deactivation_period_spec.rb b/spec/models/scheme_deactivation_period_spec.rb index bf15d7dd3..73a93de99 100644 --- a/spec/models/scheme_deactivation_period_spec.rb +++ b/spec/models/scheme_deactivation_period_spec.rb @@ -76,7 +76,10 @@ RSpec.describe SchemeDeactivationPeriod do context "when there is an open deactivation period less than six months in the future" do # validate_reactivation let!(:scheme) { FactoryBot.build(:scheme, created_at: previous_collection_start_date - 2.years) } - let!(:existing_period) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.now + 5.months, scheme:) } + + before do + FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.now + 5.months, scheme:) + end context "when reactivation date is nil" do let(:record) { FactoryBot.build(:scheme_deactivation_period, deactivation_date: Time.zone.now, scheme:) } @@ -112,9 +115,12 @@ RSpec.describe SchemeDeactivationPeriod do context "when there is not an open deactivation period within six months" do # validate_deactivation let!(:scheme) { FactoryBot.create(:scheme, created_at: previous_collection_start_date - 2.years) } - let!(:existing_period_1) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.now + 7.months, reactivation_date: Time.zone.now + 8.months, scheme:) } - let!(:existing_period_2) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.now + 1.month, reactivation_date: Time.zone.now + 2.months, scheme:) } - let!(:existing_period_3) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.now + 9.months, scheme:) } + + before do + FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.now + 7.months, reactivation_date: Time.zone.now + 8.months, scheme:) + FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.now + 1.month, reactivation_date: Time.zone.now + 2.months, scheme:) + FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.now + 9.months, scheme:) + end context "when reactivation date is nil" do let(:record) { FactoryBot.build(:scheme_deactivation_period, deactivation_date: Time.zone.now, scheme:) }