Browse Source

Extract location_deactivation factory

pull/996/head
Kat 4 years ago
parent
commit
13bd14468b
  1. 6
      spec/factories/location_deactivation.rb
  2. 14
      spec/models/location_spec.rb
  3. 4
      spec/requests/locations_controller_spec.rb

6
spec/factories/location_deactivation.rb

@ -0,0 +1,6 @@
FactoryBot.define do
factory :location_deactivation do
reactivation_date { nil }
end
end

14
spec/models/location_spec.rb

@ -125,19 +125,19 @@ RSpec.describe Location, type: :model do
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.location_deactivations << FactoryBot.create(:location_deactivation, 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.location_deactivations << LocationDeactivation.create(deactivation_date: Time.zone.local(2022, 6, 6), reactivation_date: nil)
location.location_deactivations << FactoryBot.create(:location_deactivation, deactivation_date: Time.zone.local(2022, 6, 6))
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.location_deactivations << FactoryBot.create(:location_deactivation, deactivation_date: Time.zone.local(2022, 6, 7))
location.save!
expect(location.status).to eq(:deactivated)
end
@ -145,7 +145,7 @@ RSpec.describe Location, type: :model do
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))
location.location_deactivations << FactoryBot.create(:location_deactivation, 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
@ -153,19 +153,19 @@ RSpec.describe Location, type: :model do
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.location_deactivations << FactoryBot.create(:location_deactivation, 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.location_deactivations << LocationDeactivation.create(deactivation_date: Time.zone.local(2022, 6, 6), reactivation_date: nil)
location.location_deactivations << FactoryBot.create(:location_deactivation, deactivation_date: Time.zone.local(2022, 6, 6))
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.location_deactivations << FactoryBot.create(:location_deactivation, deactivation_date: Time.zone.local(2022, 6, 7))
location.save!
expect(location.status).to eq(:deactivated)
end

4
spec/requests/locations_controller_spec.rb

@ -1412,7 +1412,7 @@ RSpec.describe LocationsController, type: :request do
end
context "with deactivated location" do
let(:location_deactivation) { LocationDeactivation.create(deactivation_date: Time.utc(2022, 10, 9)) }
let(:location_deactivation) { FactoryBot.create(:location_deactivation, deactivation_date: Time.zone.local(2022, 10, 9)) }
it "renders reactivate this location" do
expect(response).to have_http_status(:ok)
@ -1421,7 +1421,7 @@ RSpec.describe LocationsController, type: :request do
end
context "with location that's deactivating soon" do
let(:location_deactivation) { LocationDeactivation.create(deactivation_date: Time.utc(2022, 10, 12)) }
let(:location_deactivation) { FactoryBot.create(:location_deactivation, deactivation_date: Time.zone.local(2022, 10, 12)) }
it "renders reactivate this location" do
expect(response).to have_http_status(:ok)

Loading…
Cancel
Save