From 6b0de0328b8319e983e00ce7e8860518382736f5 Mon Sep 17 00:00:00 2001 From: Lorenzo Tello Date: Tue, 28 May 2024 07:37:52 +0100 Subject: [PATCH] CST-2558: newly registered participants with induction start date in payments-frozen cohort are now placed in the cohort currently open for registration --- app/forms/schools/add_participants/base_wizard.rb | 10 ++++++---- app/models/cohort.rb | 6 ++++-- spec/models/cohort_spec.rb | 14 +++++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/forms/schools/add_participants/base_wizard.rb b/app/forms/schools/add_participants/base_wizard.rb index d8223cb766e..def1b2f0717 100644 --- a/app/forms/schools/add_participants/base_wizard.rb +++ b/app/forms/schools/add_participants/base_wizard.rb @@ -465,10 +465,12 @@ def participant_cohort # NOTE: not preventing registration here just determining where to put the participant def cohort_to_place_participant if transfer? - existing_participant_cohort || existing_participant_profile&.schedule&.cohort + (existing_participant_cohort || existing_participant_profile&.schedule&.cohort).tap do |cohort| + return Cohort.active_registration_cohort if cohort.payments_frozen? + end elsif ect_participant? && induction_start_date.present? - Cohort.containing_date(induction_start_date).tap do |cohort| - return Cohort.current if cohort.blank? || cohort.npq_plus_one_or_earlier? + Cohort.for_induction_start_date(induction_start_date).tap do |cohort| + return Cohort.active_registration_cohort if cohort.blank? || cohort.npq_plus_one_or_earlier? end elsif Cohort.within_automatic_assignment_period? # true from 1/9 to end of automatic assignment period @@ -481,7 +483,7 @@ def cohort_to_place_participant Cohort.next else # default to now - but should ask the start_term question if not already asked - Cohort.current + Cohort.active_registration_cohort end end diff --git a/app/models/cohort.rb b/app/models/cohort.rb index 5d25accdf82..5eca8fcb2c7 100644 --- a/app/models/cohort.rb +++ b/app/models/cohort.rb @@ -43,10 +43,12 @@ def self.next # - Cohort.current for dates ealier than Sept 2021 or # - The previous date's year cohort if the date is before Jun or # - the cohort starting the date's year otherwise. + # If the cohort calculated is payments-frozen, the currently active for registration is returned instead. def self.for_induction_start_date(date) - return current if date < Date.new(2021, 9, 1) + cohort = current if date < Date.new(2021, 9, 1) + cohort ||= Cohort.find_by_start_year(date.month < 6 ? date.year - 1 : date.year) - Cohort.find_by_start_year(date.month < 6 ? date.year - 1 : date.year) + cohort.payments_frozen? ? active_registration_cohort : cohort end def self.previous diff --git a/spec/models/cohort_spec.rb b/spec/models/cohort_spec.rb index b7e7a973015..68bf9f816b8 100644 --- a/spec/models/cohort_spec.rb +++ b/spec/models/cohort_spec.rb @@ -58,14 +58,18 @@ describe ".for_induction_start_date" do subject { Cohort.for_induction_start_date(induction_start_date) } - context "when the provided date is earlier than 2021" do - let(:induction_start_date) { Date.new(2020, 5, 1) } + context "when the cohort calculated has been frozen for payments" do + let(:induction_start_date) { Date.new(2022, 7, 1) } - it { is_expected.to eq(Cohort.current) } + before do + Cohort.find_by_start_date(2022).update!(payments_frozen_at: Time.current) + end + + it { is_expected.to eq(Cohort.active_registration_cohort) } end - context "when the provided date is in 2021 before September" do - let(:induction_start_date) { Date.new(2021, 6, 1) } + context "when the provided date is earlier than 2021" do + let(:induction_start_date) { Date.new(2021, 9, 1) } it { is_expected.to eq(Cohort.current) } end