Browse Source

feat: fix logic and add tests fo activating soon

pull/1023/head
natdeanlewissoftwire 4 years ago
parent
commit
4feff79b94
  1. 8
      app/models/location.rb
  2. 14
      spec/models/location_spec.rb

8
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 :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 return :deactivating_soon if open_deactivation&.deactivation_date.present? && Time.zone.now < open_deactivation.deactivation_date
return :reactivating_soon if recent_deactivation&.reactivation_date.present? && Time.zone.now < recent_deactivation.reactivation_date
if recent_deactivation&.reactivation_date.present? && Time.zone.now < recent_deactivation.reactivation_date return :activating_soon if Time.zone.now < startdate
return :activating_soon if Time.zone.now < startdate
return :reactivating_soon
end
:active :active
end end

14
spec/models/location_spec.rb

@ -151,6 +151,12 @@ RSpec.describe Location, type: :model do
location.save! location.save!
expect(location.status).to eq(:reactivating_soon) expect(location.status).to eq(:reactivating_soon)
end 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
context "when there have been previous deactivations" do 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) expect(location.status).to eq(:reactivating_soon)
end 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) 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:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 5), reactivation_date: Time.zone.local(2022, 6, 2), location:)
location.save! location.save!
expect(location.status).to eq(:reactivating_soon) expect(location.status).to eq(:reactivating_soon)
end 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 end
end end

Loading…
Cancel
Save