From 4feff79b94762a5b0e400ed147208f022a2805df Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 23 Nov 2022 15:29:12 +0000 Subject: [PATCH] feat: fix logic and add tests fo activating soon --- app/models/location.rb | 8 ++------ spec/models/location_spec.rb | 14 +++++++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/models/location.rb b/app/models/location.rb index 7907c1d1b..9ca32ab85 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -379,12 +379,8 @@ class Location < ApplicationRecord return :deactivated if open_deactivation&.deactivation_date.present? && Time.zone.now >= open_deactivation.deactivation_date return :deactivating_soon if open_deactivation&.deactivation_date.present? && Time.zone.now < open_deactivation.deactivation_date - - if recent_deactivation&.reactivation_date.present? && Time.zone.now < recent_deactivation.reactivation_date - return :activating_soon if Time.zone.now < startdate - - return :reactivating_soon - end + return :reactivating_soon if recent_deactivation&.reactivation_date.present? && Time.zone.now < recent_deactivation.reactivation_date + return :activating_soon if Time.zone.now < startdate :active end diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 64a4855da..dd5d697e9 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -151,6 +151,12 @@ RSpec.describe Location, type: :model do location.save! expect(location.status).to eq(:reactivating_soon) end + + it "returns activating soon if the location has a future startdate" do + location.startdate = Time.zone.local(2022, 7, 7) + location.save! + expect(location.status).to eq(:activating_soon) + end end context "when there have been previous deactivations" do @@ -188,12 +194,18 @@ RSpec.describe Location, type: :model do expect(location.status).to eq(:reactivating_soon) end - it "returns if the location had a deactivation during another deactivation" do + it "returns reactivating soon if the location had a deactivation during another deactivation" do Timecop.freeze(2022, 6, 4) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 2), location:) location.save! expect(location.status).to eq(:reactivating_soon) end + + it "returns activating soon if the location has a future startdate" do + location.startdate = Time.zone.local(2022, 7, 7) + location.save! + expect(location.status).to eq(:activating_soon) + end end end end