Browse Source

Add status method

pull/981/head
Kat 4 years ago
parent
commit
23ad82e7ce
  1. 4
      app/models/location.rb
  2. 32
      spec/models/location_spec.rb

4
app/models/location.rb

@ -373,7 +373,9 @@ class Location < ApplicationRecord
end
def status
"active"
return :active if deactivation_date.blank?
return :deactivating_soon if Time.zone.now < deactivation_date
return :deactivated if Time.zone.now >= deactivation_date
end
private

32
spec/models/location_spec.rb

@ -111,4 +111,36 @@ RSpec.describe Location, type: :model do
end
end
end
describe "status" do
let(:location) { FactoryBot.build(:location) }
before do
Timecop.freeze(2022, 6, 7)
end
it "returns active if the location is not deactivated" do
location.deactivation_date = nil
location.save!
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.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.save!
expect(location.status).to eq(:deactivated)
end
it "returns deactivated if deactivation_date is today" do
location.deactivation_date = Time.zone.local(2022, 6, 7)
location.save!
expect(location.status).to eq(:deactivated)
end
end
end

Loading…
Cancel
Save