-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prolong J+S leiter 2021 refs hitobito/hitobito#1344
- Loading branch information
Showing
2 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
db/migrate/20211109094956_prolong_j_s_qualifications_2021.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,60 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2021, Cevi. This file is part of | ||
# hitobito_pbs and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_cevi. | ||
|
||
class ProlongJSQualifications2021 < ActiveRecord::Migration[6.0] | ||
|
||
# prolongs a fixed list of J+S qualifications due to COVID-19. | ||
# | ||
# Alle J+S-Leiterinnen und -Leiter, welche 2019 zuletzt eine J+S-Ausbildung (z.B. Leiterkurs) oder ein | ||
# J+S-Weiterbildungsmodul besucht haben, bekommen ihre Einsatzberechtigung bis Ende 2022 verlängert («gültig bis 31.12.2022»). | ||
# Dies hat der Bundesrat am 30.6.2021 entschieden, weil viele Weiterbildungsmodule aufgrund der Coronamassnahmen nicht stattfinden konnten. | ||
# Source: https://www.jugendundsport.ch/de/corona/faq.html#ui-collapse-840 | ||
# Nicht betroffen von dieser Massnahme sind J+S-Expertinnen und -Experten, J+S-Coaches sowie J+S-Leiterinnen und -Leiter, | ||
# welche letztmals 2018 oder früher in einer J+S-Aus- oder Weiterbildung absolviert haben. | ||
|
||
QUALIFICATION_KIND_LABELS = | ||
['J+S-Leiter/-in Jugend LS/T', | ||
'J+S-Leiter/-in Kinder LS/T'].freeze | ||
|
||
PROLONGED_DATE = Date.new(2022, 12, 31).freeze | ||
|
||
def up | ||
js_quali_courses_2021.find_each do |c| | ||
participant_ids = c.participations.where(qualified: true).collect(&:person_id) | ||
qualis = Qualification.where(person_id: participant_ids, | ||
qualification_kind_id: | ||
qualification_kind_ids, | ||
start_at: c.qualification_date) | ||
qualis.update_all(finish_at: PROLONGED_DATE) | ||
end | ||
end | ||
|
||
private | ||
|
||
def js_quali_courses_2021 | ||
Event::Course | ||
.joins(:dates) | ||
.joins(:kind) | ||
.includes(:participations) | ||
.between(Date.new(2019, 1, 1), Date.new(2019, 12, 31)) | ||
.where(event_kinds: { id: js_event_kind_ids }) | ||
end | ||
|
||
def js_event_kind_ids | ||
Event::KindQualificationKind | ||
.where(qualification_kind_id: qualification_kind_ids, role: 'participant') | ||
.pluck(:event_kind_id) | ||
end | ||
|
||
def qualification_kind_ids | ||
@qualification_kind_ids ||= | ||
QualificationKind | ||
.where(label: QUALIFICATION_KIND_LABELS) | ||
.pluck(:id) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2021, Cevi. This file is part of | ||
# hitobito_pbs and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_cevi | ||
|
||
require 'spec_helper' | ||
migration_file_name = Dir[Rails.root.join('../hitobito_cevi/db/migrate/20211109094956_prolong_j_s_qualifications_2021.rb')].first | ||
require migration_file_name | ||
|
||
|
||
describe ProlongJSQualifications2021 do | ||
|
||
let(:migration) { described_class.new.tap { |m| m.verbose = false } } | ||
|
||
let!(:qk_js_leiter) do | ||
QualificationKind.create!(label: 'J+S-Leiter/-in Kinder LS/T', validity: 2) | ||
end | ||
|
||
let!(:ek_qk_js_leiter) do | ||
Event::KindQualificationKind.create!(qualification_kind: qk_js_leiter, | ||
event_kind: event_kinds(:group), | ||
category: 'qualification', | ||
role: 'participant') | ||
end | ||
|
||
let!(:qk_js_coach) do | ||
QualificationKind.create!(label: 'J+S Coach', validity: 2) | ||
end | ||
|
||
let!(:ek_qk_js_coach) do | ||
Event::KindQualificationKind.create!(qualification_kind: qk_js_coach, | ||
event_kind: event_kinds(:group), | ||
category: 'qualification', | ||
role: 'participant') | ||
end | ||
|
||
let!(:event_kind_js) { Event::Kind.create!(label: 'JS', event_kind_qualification_kinds: [ek_qk_js_leiter, ek_qk_js_coach]) } | ||
|
||
let!(:js_course_2021) { create_js_course(2021) } | ||
let!(:js_course_2020) { create_js_course(2020) } | ||
let!(:js_course_2019) { create_js_course(2019) } | ||
let!(:js_course_2018) { create_js_course(2018) } | ||
|
||
let(:extension_date) { Date.new(2022, 12, 31) } | ||
|
||
context '#up' do | ||
|
||
it 'prolongs specific js qualifications completed in 2019' do | ||
migration.up | ||
|
||
js_course_2018.participations.each do |p| | ||
expect(p.person.qualifications.first.finish_at).not_to eq(extension_date) | ||
end | ||
|
||
js_course_2019.participations.each do |p| | ||
# should be prolonged (leiter) | ||
expect(qualifications(p.person, qk_js_leiter).first.finish_at).to eq(extension_date) | ||
|
||
# should not be changed (coach) | ||
expect(qualifications(p.person, qk_js_coach).first.finish_at).not_to eq(extension_date) | ||
end | ||
|
||
js_course_2020.participations.each do |p| | ||
# was already set to 2022-12-31 when issued | ||
expect(p.person.qualifications.first.finish_at).to eq(extension_date) | ||
end | ||
|
||
js_course_2021.participations.each do |p| | ||
expect(p.person.qualifications.first.finish_at).not_to eq(extension_date) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def qualifications(person, qualification_kind) | ||
person.qualifications.where(qualification_kind_id: qualification_kind) | ||
end | ||
|
||
def create_js_course(year) | ||
course = Fabricate(:cevi_course, kind: event_kind_js, dates: event_dates(year)) | ||
12.times do | ||
participation = Fabricate(:event_participation, event: course, qualified: true, state: :assigned, | ||
roles: [Event::Course::Role::Participant.new]) | ||
Event::Qualifier.for(participation).issue | ||
end | ||
course | ||
end | ||
|
||
def event_dates(year) | ||
start_at = Date.new(year, 06, 11) | ||
[Fabricate(:event_date, start_at: start_at, finish_at: start_at + 8.days)] | ||
end | ||
|
||
end |