Skip to content

Commit

Permalink
Update abo_basic_login wizard form
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr committed Oct 3, 2024
1 parent cde48ab commit 84f6699
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

module Wizards::Steps::Signup::AboBasicLogin
class PersonFields < Wizards::Steps::Signup::PersonFields
def self.agreements = [:data_protection]

include Wizards::Steps::Signup::AgreementFields

NON_ASSIGNABLE_ATTRS = Wizards::Steps::Signup::AgreementFields::AGREEMENTS + [:newsletter]
self.partial = "wizards/steps/signup/person_fields"

def requires_adult_consent? = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
# https://github.com/hitobito/hitobito_sac_cas.

module Wizards::Steps::Signup::AboTourenPortal
class PersonFields < Wizards::Steps::Signup::AboBasicLogin::PersonFields
class PersonFields < Wizards::Steps::Signup::PersonFields
include Wizards::Steps::Signup::AgreementFields

self.minimum_age = 18
self.partial = "wizards/steps/signup/person_fields"

validates :street, :housenumber, :town, :zip_code,
:country, :phone_number, presence: true

def requires_adult_consent? = false

def person_attributes
super.except(*Wizards::Steps::Signup::AboBasicLogin::PersonFields::NON_ASSIGNABLE_ATTRS)
end
end
end
12 changes: 4 additions & 8 deletions app/models/wizards/steps/signup/agreement_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ module Wizards::Steps::Signup
module AgreementFields
extend ActiveSupport::Concern

AGREEMENTS = [
:statutes,
:data_protection
].freeze
AGREEMENTS = %i[statutes data_protection].freeze

included do
include Rails.application.routes.url_helpers
class_attribute :agreements, default: AGREEMENTS unless respond_to?(:agreements)
attribute :newsletter, :boolean

AGREEMENTS.each do |agreement|
agreements.each do |agreement|
attribute agreement, :boolean, default: false
validates agreement, acceptance: true
end

attribute :newsletter, :boolean
end

def link_translations(key)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-# 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.
= render 'wizards/steps/signup/person_fields', c:
3 changes: 3 additions & 0 deletions config/locales/wagon.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,9 @@ de:
agreement_fields:
adult_consent_caption: Ich bestätige, dass ich mindestens 18 Jahre alt bin oder das Einverständnis meiner Erziehungsberechtigten habe
newsletter_caption: Ich möchte einen Newsletter abonnieren
abo_basic_login:
person_fields:
next_button: SAC-KONTO ERSTELLEN
abo_magazin:
issues_from_field_title: Abo
issues_from_field:
Expand Down
15 changes: 7 additions & 8 deletions spec/features/signup/abo_basic_login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def complete_main_person_form
fill_in "Telefon", with: "+41 79 123 45 56"
fill_in "wizards_signup_abo_basic_login_wizard_person_fields_zip_code", with: "8000"
fill_in "wizards_signup_abo_basic_login_wizard_person_fields_town", with: "Zürich"
check "Ich habe die Statuten gelesen und stimme diesen zu"
check "Ich habe die Datenschutzerklärung gelesen und stimme diesen zu"
end

Expand All @@ -44,18 +43,18 @@ def expect_validation_error(message)
allow(Truemail).to receive(:valid?).with("[email protected]").and_return(false)
visit group_self_registration_path(group_id: group.id)
fill_in "E-Mail", with: "[email protected]"
click_on "Weiter"
click_button "Weiter"
expect_active_step("E-Mail")
expect_validation_error("E-Mail ist nicht gültig")
end

it "creates person" do
visit group_self_registration_path(group_id: group.id)
fill_in "E-Mail", with: "[email protected]"
click_on "Weiter"
click_button "Weiter"
complete_main_person_form
expect do
click_on "Registrieren"
click_button "SAC-KONTO ERSTELLEN"
expect(page).to have_css "#error_explanation, #flash > .alert"
end.to change { Person.count }.by(1)
expect(Person.last.roles.last.delete_on).not_to be_nil
Expand All @@ -64,12 +63,12 @@ def expect_validation_error(message)
it "subscribes to mailinglist" do
visit group_self_registration_path(group_id: group)
fill_in "E-Mail", with: "[email protected]"
click_on "Weiter"
click_button "Weiter"
complete_main_person_form
check "Ich möchte einen Newsletter abonnieren"

expect do
click_on "Registrieren"
click_button "SAC-KONTO ERSTELLEN"
expect(page).to have_css "#error_explanation, #flash > .alert"
end.to change { Person.count }.by(1)

Expand All @@ -84,12 +83,12 @@ def expect_validation_error(message)
it "opts out of mailinglist" do
visit group_self_registration_path(group_id: group)
fill_in "E-Mail", with: "[email protected]"
click_on "Weiter"
click_button "Weiter"
complete_main_person_form
uncheck "Ich möchte einen Newsletter abonnieren"

expect do
click_on "Registrieren"
click_button "SAC-KONTO ERSTELLEN"
expect(page).to have_css "#error_explanation, #flash > .alert"
end.to change { Person.count }.by(1)

Expand Down

0 comments on commit 84f6699

Please sign in to comment.