From 3b0cc9879d10726fbe6224306616d405e65418cc Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 3 Apr 2023 12:13:18 +0100 Subject: [PATCH] Set the scheme as available from previous year if the collection is in crossover --- app/models/scheme.rb | 6 +++++- .../check_answers_summary_list_card_component_spec.rb | 4 ++-- spec/models/sales_log_spec.rb | 4 ++-- spec/models/validations/sales/setup_validations_spec.rb | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 1ab65ea32..3b2c98055 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -219,7 +219,11 @@ class Scheme < ApplicationRecord end def available_from - FormHandler.instance.collection_start_date(created_at) + if FormHandler.instance.in_crossover_period?(now: created_at) + FormHandler.instance.collection_start_date(created_at) - 1.year + else + FormHandler.instance.collection_start_date(created_at) + end end def open_deactivation diff --git a/spec/components/check_answers_summary_list_card_component_spec.rb b/spec/components/check_answers_summary_list_card_component_spec.rb index fbdb244da..8bf9f4a45 100644 --- a/spec/components/check_answers_summary_list_card_component_spec.rb +++ b/spec/components/check_answers_summary_list_card_component_spec.rb @@ -10,11 +10,11 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do Timecop.freeze(Time.zone.local(2023, 1, 10)) Singleton.__init__(FormHandler) end - + after do Timecop.return end - + context "when given a set of questions" do let(:user) { build(:user) } let(:log) { build(:lettings_log, :completed, age2: 99, startdate: Time.zone.local(2021, 5, 1)) } diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 148576b8b..3ebb16f54 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -95,11 +95,11 @@ RSpec.describe SalesLog, type: :model do Timecop.freeze(Time.zone.local(2023, 1, 10)) Singleton.__init__(FormHandler) end - + after do Timecop.return end - + it "has returns the correct form based on the start date" do expect(sales_log.form_name).to be_nil expect(sales_log.form).to be_a(Form) diff --git a/spec/models/validations/sales/setup_validations_spec.rb b/spec/models/validations/sales/setup_validations_spec.rb index dde80b662..6f70e3f1e 100644 --- a/spec/models/validations/sales/setup_validations_spec.rb +++ b/spec/models/validations/sales/setup_validations_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Validations::Sales::SetupValidations do Timecop.freeze(Time.zone.local(2023, 1, 10)) Singleton.__init__(FormHandler) end - + after do Timecop.return end