Skip to content

Commit

Permalink
Prolong J+S leiter 2021 refs hitobito/hitobito#1344
Browse files Browse the repository at this point in the history
  • Loading branch information
mtnstar committed Nov 11, 2021
1 parent 9485466 commit f237321
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 0 deletions.
60 changes: 60 additions & 0 deletions db/migrate/20211109094956_prolong_j_s_qualifications_2021.rb
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
97 changes: 97 additions & 0 deletions spec/migrations/prolong_j_s_qualifications_2021_spec.rb
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

0 comments on commit f237321

Please sign in to comment.