-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from hitobito/#1919_abo-filter
PERSON: Abo-Filter nach Alter und Sprache
- Loading branch information
Showing
26 changed files
with
124 additions
and
65 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
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
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
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
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
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
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
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
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
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
37 changes: 37 additions & 0 deletions
37
db/migrate/20230915105810_replace_correspondence_language_with_core_language.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,37 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2023, Pfadibewegung Schweiz. 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_pbs. | ||
|
||
class ReplaceCorrespondenceLanguageWithCoreLanguage < ActiveRecord::Migration[6.1] | ||
CANTONS_LANGUAGE = { | ||
# de: [:ag, :ai, :ar, :be, :bl, :bs, :gl, :gr, :lu, :nw, :ow, :sg, :sh, :so, :sz, :tg, :ur, :zg, :zh], | ||
fr: [:fr, :ge, :ju, :ne, :vd, :vs], | ||
it: [:ti] | ||
}.freeze | ||
|
||
def up | ||
Person.where.not(correspondence_language: nil).update_all("language = correspondence_language") | ||
Person.where(correspondence_language: nil).find_each do |person| | ||
person.update!(language: infer_person_language(person)) | ||
end | ||
|
||
remove_column :people, :correspondence_language, :string, limit: 5 | ||
end | ||
|
||
def down | ||
add_column :people, :correspondence_language, :string, limit: 5 | ||
Person.update_all("correspondence_language = language") | ||
end | ||
|
||
def infer_person_language(person) | ||
return person.language if person.language.present? | ||
return person.correspondence_language if person.try(:correspondence_language).present? | ||
|
||
kv = person.send(:find_kantonalverband)&.becomes(Group::Kantonalverband) | ||
canton = kv&.kantonalverband_cantons&.first&.to_s&.downcase&.to_sym | ||
CANTONS_LANGUAGE.find { |language, cantons| cantons.include?(canton) }&.first || :de | ||
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2023, Pfadibewegung Schweiz. 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_pbs. | ||
|
||
require 'spec_helper' | ||
require Rails.root.join('../hitobito_pbs/db/migrate/20230915105810_replace_correspondence_language_with_core_language.rb') | ||
|
||
describe ReplaceCorrespondenceLanguageWithCoreLanguage do | ||
subject(:migration) { described_class.new.tap { |migration| migration.verbose = false } } | ||
|
||
describe '#infer_person_language' do | ||
let(:person) { Fabricate(:person) } | ||
let(:language) { nil } | ||
let(:correspondence_language) { nil } | ||
subject(:infer_person_language) { migration.infer_person_language(person) } | ||
|
||
before do | ||
allow(person).to receive(:language).and_return(language) | ||
allow(person).to receive(:correspondence_language).and_return(correspondence_language) | ||
end | ||
|
||
context 'with existing language' do | ||
let(:language) { :test } | ||
it { expect(infer_person_language).to eq(language) } | ||
end | ||
|
||
context 'with existing correspondance_language' do | ||
let(:correspondence_language) { :test } | ||
it { expect(infer_person_language).to eq(:test) } | ||
end | ||
|
||
context 'with language from KV' do | ||
let(:person) { Fabricate(Group::Kantonalverband::Coach.name, group: kv).person } | ||
let(:kv) do | ||
Fabricate(Group::Kantonalverband.name, parent: groups(:bund)).tap do |kv| | ||
kv.kantonalverband_cantons.create!(canton: canton) | ||
end | ||
end | ||
|
||
context 'with KV ti' do | ||
let(:canton) { :ti } | ||
it { expect(infer_person_language).to eq(:it) } | ||
end | ||
|
||
context 'with KV ju' do | ||
let(:canton) { :ju } | ||
it { expect(infer_person_language).to eq(:fr) } | ||
end | ||
|
||
context 'with KV be' do | ||
let(:canton) { :be } | ||
it { expect(infer_person_language).to eq(:de) } | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.