Browse Source

Update logs status determination for location

pull/996/head
Kat 4 years ago
parent
commit
1289f20ccf
  1. 6
      app/models/location.rb
  2. 1
      app/models/location_deactivation.rb
  3. 68
      spec/models/location_spec.rb

6
app/models/location.rb

@ -375,9 +375,9 @@ class Location < ApplicationRecord
end
def status
return :active if location_deactivations.count == 0
return :deactivating_soon if Time.zone.now < location_deactivations.first.deactivation_date
return :deactivated
recent_deactivation = location_deactivations.deactivations_without_reactivation.first
return :active unless recent_deactivation.present?
return :deactivating_soon if Time.zone.now < recent_deactivation.deactivation_date
:deactivated
end

1
app/models/location_deactivation.rb

@ -1,2 +1,3 @@
class LocationDeactivation < ApplicationRecord
scope :deactivations_without_reactivation, ->() { where(reactivation_date: nil) }
end

68
spec/models/location_spec.rb

@ -119,32 +119,56 @@ RSpec.describe Location, type: :model do
Timecop.freeze(2022, 6, 7)
end
it "returns active if the location is not deactivated" do
location.deactivation_date = nil
location.deactivation_date_type = nil
location.save!
expect(location.status).to eq(:active)
end
context "when there have not been any previous deactivations" do
it "returns active if the location has no deactivation records" do
expect(location.status).to eq(:active)
end
it "returns deactivating soon if deactivation_date is in the future" do
location.deactivation_date = Time.zone.local(2022, 8, 8)
location.deactivation_date_type = "other"
location.save!
expect(location.status).to eq(:deactivating_soon)
end
it "returns deactivating soon if deactivation_date is in the future" do
location.location_deactivations << LocationDeactivation.create(deactivation_date: Time.zone.local(2022, 8, 8), reactivation_date: nil)
location.save!
expect(location.status).to eq(:deactivating_soon)
end
it "returns deactivated if deactivation_date is in the past" do
location.deactivation_date = Time.zone.local(2022, 4, 8)
location.deactivation_date_type = "other"
location.save!
expect(location.status).to eq(:deactivated)
it "returns deactivated if deactivation_date is in the past" do
location.location_deactivations << LocationDeactivation.create(deactivation_date: Time.zone.local(2022, 6, 6), reactivation_date: nil)
location.save!
expect(location.status).to eq(:deactivated)
end
it "returns deactivated if deactivation_date is today" do
location.location_deactivations << LocationDeactivation.create(deactivation_date: Time.zone.local(2022, 6, 7), reactivation_date: nil)
location.save!
expect(location.status).to eq(:deactivated)
end
end
it "returns deactivated if deactivation_date is today" do
location.deactivation_date = Time.zone.local(2022, 6, 7)
location.deactivation_date_type = "other"
location.save!
expect(location.status).to eq(:deactivated)
context "when there have been previous deactivations" do
before do
location.location_deactivations << LocationDeactivation.create(deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 6, 5))
end
it "returns active if the location has no relevant deactivation records" do
expect(location.status).to eq(:active)
end
it "returns deactivating soon if deactivation_date is in the future" do
location.location_deactivations << LocationDeactivation.create(deactivation_date: Time.zone.local(2022, 8, 8), reactivation_date: nil)
location.save!
expect(location.status).to eq(:deactivating_soon)
end
it "returns deactivated if deactivation_date is in the past" do
location.location_deactivations << LocationDeactivation.create(deactivation_date: Time.zone.local(2022, 6, 6), reactivation_date: nil)
location.save!
expect(location.status).to eq(:deactivated)
end
it "returns deactivated if deactivation_date is today" do
location.location_deactivations << LocationDeactivation.create(deactivation_date: Time.zone.local(2022, 6, 7), reactivation_date: nil)
location.save!
expect(location.status).to eq(:deactivated)
end
end
end

Loading…
Cancel
Save