diff --git a/app/models/recruitment_cycle_timetable.rb b/app/models/recruitment_cycle_timetable.rb index d9e7276d2b9..0525ce596d6 100644 --- a/app/models/recruitment_cycle_timetable.rb +++ b/app/models/recruitment_cycle_timetable.rb @@ -54,16 +54,14 @@ def cycle_range end def sequential_dates - required_dates = [ + return if [ find_opens_at, apply_opens_at, apply_deadline_at, reject_by_default_at, decline_by_default_at, find_closes_at, - ] - - return if required_dates.any?(&:blank?) + ].any?(&:blank?) if find_opens_at > apply_opens_at errors.add(:apply_opens_at, :apply_opens_after_find_opens) diff --git a/app/services/data_migrations/add_all_recruitment_cycle_timetables_to_database.rb b/app/services/data_migrations/add_all_recruitment_cycle_timetables_to_database.rb new file mode 100644 index 00000000000..8046c1dd366 --- /dev/null +++ b/app/services/data_migrations/add_all_recruitment_cycle_timetables_to_database.rb @@ -0,0 +1,22 @@ +module DataMigrations + class AddAllRecruitmentCycleTimetablesToDatabase + TIMESTAMP = 20250129093844 + MANUAL_RUN = false + + def change + CYCLE_DATES.each do |recruitment_cycle_year, dates| + RecruitmentCycleTimetable.create( + recruitment_cycle_year:, + find_opens_at: dates[:find_opens], + apply_opens_at: dates[:apply_opens], + apply_deadline_at: dates[:apply_deadline], + reject_by_default_at: dates[:reject_by_default], + decline_by_default_at: dates[:find_closes] - 1.day, + find_closes_at: dates[:find_closes], + christmas_holiday_range: dates.dig(:holidays, :christmas), + easter_holiday_range: dates.dig(:holidays, :easter), + ) + end + end + end +end diff --git a/config/initializers/cycle_timetables.rb b/config/initializers/cycle_timetables.rb index 13ba9f3842d..2fff2872b57 100644 --- a/config/initializers/cycle_timetables.rb +++ b/config/initializers/cycle_timetables.rb @@ -37,7 +37,7 @@ reject_by_default: Time.zone.local(2026, 9, 24, 23, 59, 59), # CONFIRMED find_closes: Time.zone.local(2026, 9, 30, 23, 59, 59), # CONFIRMED holidays: { - christmas: Date.new(2026, 12, 18)..Date.new(2026, 1, 5), # TBD + christmas: Date.new(2025, 12, 18)..Date.new(2026, 1, 5), # TBD easter: Date.new(2026, 3, 23)..Date.new(2026, 4, 6), # TBD }, }, @@ -55,7 +55,7 @@ find_closes: Time.zone.local(2027, 9, 30, 23, 59, 59), # TBD holidays: { christmas: Date.new(2026, 12, 18)..Date.new(2027, 1, 5), # TBD - easter: Date.new(2026, 3, 15)..Date.new(2027, 3, 29), # TBD + easter: Date.new(2027, 3, 15)..Date.new(2027, 3, 29), # TBD }, }, }.freeze @@ -79,7 +79,7 @@ apply_1_deadline: Time.zone.local(2020, 8, 24, 18), apply_2_deadline: Time.zone.local(2020, 9, 18, 18), apply_deadline: Time.zone.local(2020, 9, 18, 18), # Adding an 'apply_deadline' for backward compatibility. - reject_by_default: Time.zone.local(2021, 9, 29, 23, 59, 59), + reject_by_default: Time.zone.local(2020, 9, 29, 23, 59, 59), find_closes: Time.zone.local(2020, 10, 3, 23, 59, 59), holidays: {}, }, diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index d9d5773e850..fe9030d2a9b 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -1,5 +1,6 @@ DATA_MIGRATION_SERVICES = [ # do not delete or edit this line - services added below by generator + 'DataMigrations::AddAllRecruitmentCycleTimetablesToDatabase', 'DataMigrations::RemoveOneLoginPreReleaseBannersFeatureFlag', 'DataMigrations::RemoveNewWithdrawalReasonsFeatureFlag', 'DataMigrations::RemoveUnusedFeatureFlags', diff --git a/spec/services/data_migrations/add_all_recruitment_cycle_timetables_to_database_spec.rb b/spec/services/data_migrations/add_all_recruitment_cycle_timetables_to_database_spec.rb new file mode 100644 index 00000000000..76d70c461e7 --- /dev/null +++ b/spec/services/data_migrations/add_all_recruitment_cycle_timetables_to_database_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe DataMigrations::AddAllRecruitmentCycleTimetablesToDatabase do + it 'adds all recruitment cycles to database' do + described_class.new.change + expect(RecruitmentCycleTimetable.pluck(:recruitment_cycle_year)) + .to contain_exactly(2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027) + end + + it 'handles holidays as expected' do + described_class.new.change + year_without_holidays = RecruitmentCycleTimetable.find_by(recruitment_cycle_year: 2020) + year_with_holidays = RecruitmentCycleTimetable.find_by(recruitment_cycle_year: 2021) + + expect(year_without_holidays.easter_holiday_range).to be_nil + expect(year_without_holidays.christmas_holiday_range).to be_nil + + expect(year_with_holidays.easter_holiday_range.begin).to eq Date.new(2021, 4, 2) + expect(year_with_holidays.easter_holiday_range.end).to eq Date.new(2021, 4, 17) + + expect(year_with_holidays.christmas_holiday_range.begin).to eq Date.new(2020, 12, 20) + expect(year_with_holidays.christmas_holiday_range.end).to eq Date.new(2021, 1, 2) + end +end