Browse Source

Allow deactivations and reactivations from available from date instead of start of the collection date

pull/1007/head
Kat 4 years ago
parent
commit
6af980d175
  1. 10
      app/models/location.rb
  2. 8
      spec/models/location_spec.rb
  3. 6
      spec/requests/locations_controller_spec.rb

10
app/models/location.rb

@ -425,9 +425,8 @@ class Location < ApplicationRecord
errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.invalid")) errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.invalid"))
end end
else else
collection_start_date = FormHandler.instance.current_collection_start_date unless deactivation_date.between?(available_from, Time.zone.local(2200, 1, 1))
unless deactivation_date.between?(collection_start_date, Time.zone.local(2200, 1, 1)) errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.out_of_range", date: available_from.to_formatted_s(:govuk_date)))
errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.out_of_range", date: collection_start_date.to_formatted_s(:govuk_date)))
end end
end end
end end
@ -447,9 +446,8 @@ class Location < ApplicationRecord
errors.add(:reactivation_date, message: I18n.t("validations.location.toggle_date.invalid")) errors.add(:reactivation_date, message: I18n.t("validations.location.toggle_date.invalid"))
end end
else else
collection_start_date = FormHandler.instance.current_collection_start_date if !reactivation_date.between?(available_from, Time.zone.local(2200, 1, 1))
if !reactivation_date.between?(collection_start_date, Time.zone.local(2200, 1, 1)) errors.add(:reactivation_date, message: I18n.t("validations.location.toggle_date.out_of_range", date: available_from.to_formatted_s(:govuk_date)))
errors.add(:reactivation_date, message: I18n.t("validations.location.toggle_date.out_of_range", date: collection_start_date.to_formatted_s(:govuk_date)))
elsif reactivation_date < recent_deactivation.deactivation_date elsif reactivation_date < recent_deactivation.deactivation_date
errors.add(:reactivation_date, message: I18n.t("validations.location.reactivation.before_deactivation", date: recent_deactivation.deactivation_date.to_formatted_s(:govuk_date))) errors.add(:reactivation_date, message: I18n.t("validations.location.reactivation.before_deactivation", date: recent_deactivation.deactivation_date.to_formatted_s(:govuk_date)))
end end

8
spec/models/location_spec.rb

@ -264,12 +264,4 @@ RSpec.describe Location, type: :model do
end end
end end
end end
describe "with deactivation_date (but no deactivation_date_type)" do
let(:location) { FactoryBot.create(:location, deactivation_date: Date.new(2022, 4, 1)) }
it "is valid" do
expect(location).to be_valid
end
end
end end

6
spec/requests/locations_controller_spec.rb

@ -1238,10 +1238,10 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:location) { FactoryBot.create(:location, scheme:) } let!(:location) { FactoryBot.create(:location, scheme:, startdate: nil, created_at: Time.zone.local(2022, 4, 1)) }
let(:deactivation_date) { Time.utc(2022, 10, 10) } let(:deactivation_date) { Time.utc(2022, 10, 10) }
let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) } let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) }
let(:startdate) { Time.utc(2022, 10, 11) } let(:startdate) { Time.utc(2022, 10, 11) }
before do before do
Timecop.freeze(Time.utc(2022, 10, 10)) Timecop.freeze(Time.utc(2022, 10, 10))
@ -1477,7 +1477,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:location) { FactoryBot.create(:location, scheme:) } let!(:location) { FactoryBot.create(:location, scheme:, startdate: nil) }
let(:deactivation_date) { Time.zone.local(2022, 4, 1) } let(:deactivation_date) { Time.zone.local(2022, 4, 1) }
let(:startdate) { Time.utc(2022, 10, 11) } let(:startdate) { Time.utc(2022, 10, 11) }

Loading…
Cancel
Save