Skip to content

Commit

Permalink
CST-2558: newly registered participants with induction start date in …
Browse files Browse the repository at this point in the history
…payments-frozen cohort are now placed in the cohort currently open for registration
  • Loading branch information
ltello committed May 28, 2024
1 parent 8bbfa0c commit 99dbfed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/forms/schools/add_participants/base_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def cohort_to_place_participant
if transfer?
existing_participant_cohort || existing_participant_profile&.schedule&.cohort
elsif ect_participant? && induction_start_date.present?
Cohort.containing_date(induction_start_date).tap do |cohort|
Cohort.for_induction_start_date(induction_start_date).tap do |cohort|
return Cohort.current if cohort.blank? || cohort.npq_plus_one_or_earlier?
end
elsif Cohort.within_automatic_assignment_period?
Expand Down
6 changes: 4 additions & 2 deletions app/models/cohort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions spec/models/cohort_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "rails_helper"

RSpec.describe Cohort, type: :model do
let!(:cohort_2024) { FactoryBot.create :seed_cohort, start_year: 2024 }
let!(:cohort_2024) { Cohort.find_by_start_year(2024) }

describe "associations" do
it { is_expected.to have_many(:call_off_contracts) }
Expand Down Expand Up @@ -58,10 +58,14 @@
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_year(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
Expand Down

0 comments on commit 99dbfed

Please sign in to comment.