-
Notifications
You must be signed in to change notification settings - Fork 19
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 #80 from hitobito/feature/hitobito_youth#58
feat: add default ahv question for #58
- Loading branch information
Showing
12 changed files
with
338 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2012-2021, Jungwacht Blauring Schweiz. This file is part of | ||
# hitobito 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. | ||
|
||
class AhvNumberValidator < ActiveModel::EachValidator | ||
require_dependency "social_security_number" | ||
include ::SocialSecurityNumber | ||
|
||
AHV_NUMBER_REGEX = /\A\d{3}\.\d{4}\.\d{4}\.\d{2}\z/ | ||
|
||
def validate_each(record, attribute, value) | ||
return if value.blank? | ||
|
||
if !AHV_NUMBER_REGEX.match?(value) | ||
record.errors.add(attribute, :must_be_social_security_number_with_correct_format) | ||
return | ||
end | ||
unless checksum_validate(value).valid? | ||
record.errors.add(attribute, :must_be_social_security_number_with_correct_checksum) | ||
end | ||
end | ||
|
||
def checksum_validate(ahv_number, country_code: "ch") | ||
SocialSecurityNumber::Validator.new(number: ahv_number.to_s, country_code:) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2012-2021, Jungwacht Blauring Schweiz. This file is part of | ||
# hitobito 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. | ||
|
||
# == Schema Information | ||
# | ||
# Table name: event_questions | ||
# | ||
# id :integer not null, primary key | ||
# admin :boolean default(FALSE), not null | ||
# choices :string(255) | ||
# multiple_choices :boolean default(FALSE), not null | ||
# question :text(65535) | ||
# required :boolean default(FALSE), not null | ||
# event_id :integer | ||
# | ||
# Indexes | ||
# | ||
# index_event_questions_on_event_id (event_id) | ||
# | ||
|
||
class Event::Question::AhvNumber < Event::Question | ||
def validate_answer(answer) | ||
validator = AhvNumberValidator.new(attributes: :answer) | ||
validator.validate(answer) | ||
end | ||
|
||
def translation_class | ||
# ensures globalize works with STI | ||
Event::Question.globalize_translation_class | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) 2012-2024, Jungwacht Blauring Schweiz. This file is part of | ||
# hitobito_jubla 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_jubla. | ||
|
||
Event::Question.create_with_translations([ | ||
{ | ||
disclosure: nil, # Has to be chosen for every event | ||
event_type: nil, # Is derived for every event | ||
type: Event::Question::AhvNumber.sti_name, | ||
translation_attributes: [ | ||
{ locale: 'de', question: 'AHV-Nummer?' }, | ||
{ locale: 'fr', question: 'Numéro AVS ?' }, | ||
{ locale: 'it', question: 'Numero AVS?' }, | ||
{ locale: 'en', question: 'AVS number?' } | ||
] | ||
}, | ||
]) |
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 |
---|---|---|
|
@@ -21,21 +21,23 @@ | |
AdditionalEmail.new(label: 'vater', email: '[email protected]', mailings: true) | ||
end | ||
|
||
subject { described_class.mailing_list_subscribers(mailing_list) } | ||
subject(:subscribers) { described_class.mailing_list_subscribers(mailing_list) } | ||
|
||
context 'default strategy' do | ||
it 'returns all people and their manager' do | ||
manager = Fabricate(:person) | ||
person.managers = [manager] | ||
|
||
subscribers = subject | ||
expect(subscribers.count).to eq(2) | ||
|
||
managed_subscriber = subscribers.first | ||
manager_subscriber = subscribers.last | ||
managed_subscriber = subscribers.find { _1.person == person } | ||
manager_subscriber = subscribers.find { _1.person == manager } | ||
|
||
expect(managed_subscriber).to be_present | ||
expect(managed_subscriber.email).to eq(person.email) | ||
expect(managed_subscriber.person).to eq(person) | ||
|
||
expect(manager_subscriber).to be_present | ||
expect(manager_subscriber.email).to eq(manager.email) | ||
expect(manager_subscriber.person).to eq(manager) | ||
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,105 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2012-2024, Jungwacht Blauring Schweiz. This file is part of | ||
# hitobito 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. | ||
|
||
require "spec_helper" | ||
|
||
describe EventsController, js: true do | ||
let(:event) do | ||
Fabricate(:event, groups: [groups(:top_group)]).tap do |event| | ||
event.dates.create!(start_at: 10.days.ago, finish_at: 5.days.ago) | ||
end | ||
end | ||
let(:global_questions) do | ||
{ | ||
ahv_number: Event::Question::AhvNumber.create!(question: "AHV-Number?", event_type: nil, disclosure: nil), | ||
} | ||
end | ||
|
||
def click_save | ||
all("form .btn-group").first.click_button "Speichern" | ||
end | ||
|
||
def click_next | ||
all(".bottom .btn-group").first.click_button "Weiter" | ||
end | ||
|
||
def click_signup | ||
all(".bottom .btn-group").first.click_button "Anmelden" | ||
end | ||
|
||
def find_question_field(question) | ||
page.all(".fields").find { |question_element| question_element.text.start_with?(question.question) } | ||
end | ||
|
||
describe "global Event::Question::AhvNumber" do | ||
subject(:question_fields_element) do | ||
click_link I18n.t("event.participations.application_answers") | ||
page.find("#application_questions_fields") | ||
end | ||
|
||
before do | ||
Event::Question.delete_all | ||
global_questions | ||
sign_in | ||
visit edit_group_event_path(event.group_ids.first, event.id) | ||
end | ||
|
||
it "includes global questions with matching event type" do | ||
is_expected.to have_text(global_questions[:ahv_number].question) | ||
|
||
is_expected.not_to have_text('Mögliche Antworten') | ||
is_expected.not_to have_text('Mehrfachauswahl') | ||
is_expected.not_to have_text('Entfernen') | ||
end | ||
end | ||
|
||
describe "answers for global questions" do | ||
let(:user) { people(:bottom_member) } | ||
let(:event_with_questions) do | ||
event.init_questions | ||
event.application_questions.map { |question| question.update!(disclosure: question.disclosure || :optional) } | ||
event.save! | ||
event | ||
end | ||
|
||
subject { page } | ||
|
||
before do | ||
Event::Question.delete_all | ||
global_questions | ||
event_with_questions | ||
sign_in(user) | ||
visit contact_data_group_event_participations_path(event.group_ids.first, event.id, event_role: {type: Event::Role::Participant}) | ||
click_next | ||
end | ||
|
||
it "fails with empty required question" do | ||
sleep 0.5 # avoid wizard race condition | ||
|
||
within find_question_field(global_questions[:ahv_number]) do | ||
answer_element = find('input[type="text"]') | ||
answer_element.fill_in(with: "Not An AHV-Number") | ||
end | ||
click_signup | ||
is_expected.to have_content "Antwort muss im gültigen Format sein (756.1234.5678.97)" | ||
|
||
within find_question_field(global_questions[:ahv_number]) do | ||
answer_element = find('input[type="text"]') | ||
answer_element.fill_in(with: "756.1234.5678.90") | ||
end | ||
click_signup | ||
is_expected.to have_content "Antwort muss eine gültige Prüfziffer haben." | ||
|
||
within find_question_field(global_questions[:ahv_number]) do | ||
answer_element = find('input[type="text"]') | ||
answer_element.fill_in(with: "756.1234.5678.97") | ||
end | ||
click_signup | ||
is_expected.to have_content "Teilnahme von Bottom Member in Eventus wurde erfolgreich erstellt." | ||
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
Oops, something went wrong.