Browse Source

use before do instead of let for unreferenced variables

pull/2995/head
Carolyn 2 months ago
parent
commit
ea7b757b29
  1. 14
      spec/models/location_deactivation_period_spec.rb
  2. 14
      spec/models/scheme_deactivation_period_spec.rb

14
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 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!(: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 context "when reactivation date is nil" do
let(:record) { FactoryBot.build(:location_deactivation_period, deactivation_date: Time.zone.now, location:) } 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 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!(: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:) } before do
let!(:existing_period_3) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.now + 9.months, location:) } 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 context "when reactivation date is nil" do
let(:record) { FactoryBot.build(:location_deactivation_period, deactivation_date: Time.zone.now, location:) } let(:record) { FactoryBot.build(:location_deactivation_period, deactivation_date: Time.zone.now, location:) }

14
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 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!(: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 context "when reactivation date is nil" do
let(:record) { FactoryBot.build(:scheme_deactivation_period, deactivation_date: Time.zone.now, scheme:) } 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 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!(: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:) } before do
let!(:existing_period_3) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.now + 9.months, scheme:) } 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 context "when reactivation date is nil" do
let(:record) { FactoryBot.build(:scheme_deactivation_period, deactivation_date: Time.zone.now, scheme:) } let(:record) { FactoryBot.build(:scheme_deactivation_period, deactivation_date: Time.zone.now, scheme:) }

Loading…
Cancel
Save