Skip to content

Commit

Permalink
Merge pull request #310 from hitobito/task/2404-self-reg-adult-consen…
Browse files Browse the repository at this point in the history
…t-required

Add adult consent to both self reg forms, refs hitobito/hitobito#2404
  • Loading branch information
mtnstar committed Feb 21, 2024
2 parents e437bc2 + d2212e6 commit 3606061
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/models/self_registration_neuanmeldung/main_person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


class SelfRegistrationNeuanmeldung::MainPerson < SelfRegistrationNeuanmeldung::Person

self.attrs = [
:first_name, :last_name, :email, :gender, :birthday,
:address, :zip_code, :town, :country,
Expand All @@ -24,6 +25,7 @@ class SelfRegistrationNeuanmeldung::MainPerson < SelfRegistrationNeuanmeldung::P
]

include FutureRole::FormHandling
include SelfRegistration::AdultConsent

delegate :newsletter, :self_registration_reason_id, to: :supplements, allow_nil: true
delegate :salutation_label, :phone_numbers, to: :person
Expand Down
4 changes: 4 additions & 0 deletions app/views/groups/self_registration/_supplements.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
= ff.inline_radio_button :self_registration_reason_id, key, label
%br

= f.fields_for(:main_person) do |fp|
= render 'adult_consent_field', f: fp

= ff.labeled(:others, '&nbsp;'.html_safe) do
= ff.label(:newsletter, class: 'd-block mt-2') do
= ff.check_box :newsletter
Expand All @@ -22,6 +25,7 @@
- if ff.object.sektion_statuten_attached?
= render 'agreement_link', f: ff, key: :sektion_statuten, link: link_to(*ff.object.sektion_statuten_link_args)


.btn-toolbar.bottom
= submit_button(f, t('groups.self_registration.form.submit'))
= c.back_link
29 changes: 28 additions & 1 deletion spec/features/self_registration_neuanmeldung_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,40 @@ def complete_last_page
end
end

describe 'with adult consent' do
let(:adult_consent_field) { page.find_field(adult_consent_text) }
let(:adult_consent_text) do
'Ich bestätige dass ich mindestens 18 Jahre alt bin oder das Einverständnis meiner Erziehungsberechtigten habe.'
end

before do
group.update!(self_registration_require_adult_consent: true)
visit group_self_registration_path(group_id: group)
complete_main_person_form
click_on 'Weiter als Einzelmitglied', match: :first
end

it 'cannot complete without accepting adult consent' do
expect { complete_last_page }.not_to change { Person.count }
expect(adult_consent_field.native.attribute('validationMessage')).to eq 'Please check this box if you want to proceed.'
end

it 'can complete when accepting adult consent' do
expect do
complete_last_page do
check adult_consent_text
end
end.to change { Person.count }.by(1)
end
end

describe 'with section privacy policy' do
before do
file = Rails.root.join('spec', 'fixtures', 'files', 'images', 'logo.png')
image = ActiveStorage::Blob.create_and_upload!(io: File.open(file, 'rb'),
filename: 'logo.png',
content_type: 'image/png').signed_id
group.layer_group.update(privacy_policy: image)
group.layer_group.update!(privacy_policy: image)
visit group_self_registration_path(group_id: group)
complete_main_person_form
click_on 'Weiter als Einzelmitglied', match: :first
Expand Down
25 changes: 24 additions & 1 deletion spec/features/self_registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,32 @@ def complete_main_person_form
expect(current_path).to eq("#{group_person_path(group_id: group, id: person, locale: :de)}.html")
end

describe 'with privacy policy' do
describe 'with adult consent' do
let(:adult_consent_field) { page.find_field(adult_consent_text) }
let(:adult_consent_text) do
'Ich bestätige dass ich mindestens 18 Jahre alt bin oder das Einverständnis meiner Erziehungsberechtigten habe.'
end

before do
group.update!(self_registration_require_adult_consent: true)
visit group_self_registration_path(group_id: group)
end

it 'cannot complete without accepting adult consent' do
complete_main_person_form
expect { click_on 'Registrieren' }.not_to(change { Person.count })
expect(adult_consent_field.native.attribute('validationMessage')).to eq 'Please check this box if you want to proceed.'
end

it 'can complete when accepting adult consent' do
complete_main_person_form
check adult_consent_text
expect { click_on 'Registrieren' }.to change { Person.count }.by(1)
end
end

describe 'with privacy policy' do
before do
file = Rails.root.join('spec', 'fixtures', 'files', 'images', 'logo.png')
image = ActiveStorage::Blob.create_and_upload!(io: File.open(file, 'rb'),
filename: 'logo.png',
Expand Down
40 changes: 40 additions & 0 deletions spec/models/self_registration/main_person_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas 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_sac_cas.

require 'spec_helper'

describe SelfRegistration::MainPerson do
subject(:model) { described_class.new }
let(:group) { groups(:geschaeftsstelle) }
let(:required_attrs) { { first_name: 'test', last_name: 'dummy' } }

context 'with group requiring adult consent' do
before do
group.update!(
self_registration_require_adult_consent: true,
self_registration_role_type: group.role_types.first
)
model.primary_group = group
model.attributes = required_attrs
end

it 'is valid when adult consent is not explicitly denied' do
expect(model).to be_valid
end

it 'is valid when adult consent is explicitly set' do
model.adult_consent = '1'
expect(model).to be_valid
end

it 'is invalid when adult consent is explicitly denied' do
model.adult_consent = '0'
expect(model).not_to be_valid
expect(model).to have(1).error_on(:adult_consent)
end
end
end
24 changes: 24 additions & 0 deletions spec/models/self_registration_neuanmeldung/main_person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
describe SelfRegistrationNeuanmeldung::MainPerson do
subject(:model) { described_class.new }
subject(:role) { model.role }
let(:sektion) { groups(:bluemlisalp_neuanmeldungen_sektion) }

describe 'attribute assignments accept additiional attributes' do
it 'works via constructor for symbols' do
Expand Down Expand Up @@ -66,6 +67,29 @@
model.attributes = required_attrs
expect(model).to be_valid
end

context 'with group requiring adult consent' do
before do
sektion.update!(self_registration_require_adult_consent: true)
model.primary_group = sektion
model.attributes = required_attrs
end

it 'is valid when adult consent is not explicitly denied' do
expect(model).to be_valid
end

it 'is valid when adult consent is explicitly set' do
model.adult_consent = '1'
expect(model).to be_valid
end

it 'is invalid when adult consent is explicitly denied' do
model.adult_consent = '0'
expect(model).not_to be_valid
expect(model).to have(1).error_on(:adult_consent)
end
end
end

describe 'delegations' do
Expand Down

0 comments on commit 3606061

Please sign in to comment.