-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Data migrations for adding recruitment cycles to database
- Loading branch information
Showing
5 changed files
with
52 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/services/data_migrations/add_all_recruitment_cycle_timetables_to_database.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
spec/services/data_migrations/add_all_recruitment_cycle_timetables_to_database_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |