From 49fc3edbd711667517f5a55516303b2b01b93adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Tue, 17 Dec 2024 14:26:51 +0100 Subject: [PATCH 01/13] Do not include main email step when logged in and build as current_user --- .../wizards/signup/abo_basic_login_wizard.rb | 34 +++++++++++++++++-- .../abo_magazin/_person_info_table.html.haml | 2 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/models/wizards/signup/abo_basic_login_wizard.rb b/app/models/wizards/signup/abo_basic_login_wizard.rb index 9b19088c8..dd13be516 100644 --- a/app/models/wizards/signup/abo_basic_login_wizard.rb +++ b/app/models/wizards/signup/abo_basic_login_wizard.rb @@ -20,7 +20,11 @@ class AboBasicLoginWizard < Wizards::RegisterNewUserWizard self.asides = ["aside_abo_basic_login"] def save! - super + if current_user.present? + person.save! + else + super + end mailing_list&.subscribe_if(person, newsletter) end @@ -28,8 +32,15 @@ def save! private def build_person - super do |_person, role| - role.end_on = Date.current.end_of_year + if current_user.present? + person = current_user.tap do |person| + role = person.roles.build(group: group, type: group.self_registration_role_type) + yield person, role if block_given? + end + else + super do |_person, role| + role.end_on = Date.current.end_of_year + end end end @@ -39,6 +50,23 @@ def person_attributes .merge(main_email_field.attributes) end + def step_after(step_class_or_name) + case step_class_or_name + when :_start + handle_start + else + super + end + end + + def handle_start + if current_user.present? + Wizards::Steps::Signup::AboBasicLogin::PersonFields.step_name + else + Wizards::Steps::Signup::MainEmailField.step_name + end + end + def mailing_list = MailingList.find_by(id: Group.root.sac_newsletter_mailing_list_id) end end diff --git a/app/views/wizards/steps/signup/abo_magazin/_person_info_table.html.haml b/app/views/wizards/steps/signup/abo_magazin/_person_info_table.html.haml index e3e70d5d5..fbb9367f0 100644 --- a/app/views/wizards/steps/signup/abo_magazin/_person_info_table.html.haml +++ b/app/views/wizards/steps/signup/abo_magazin/_person_info_table.html.haml @@ -20,7 +20,7 @@ %td=person.last_name %tr %td=t("activemodel.attributes.wizards/steps/signup/main_email_field.email") - %td=wizard.main_email_field.email + %td=person.email || wizard.main_email_field.email %tr %td=person.class.human_attribute_name(:birthday) %td=person.birthday.strftime("%d.%m.%Y") From b348f6c6e4cf886f1f8898030f3e906268517a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Tue, 17 Dec 2024 15:54:14 +0100 Subject: [PATCH 02/13] Simplify build_person method --- app/models/wizards/signup/abo_basic_login_wizard.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/wizards/signup/abo_basic_login_wizard.rb b/app/models/wizards/signup/abo_basic_login_wizard.rb index dd13be516..1ca624941 100644 --- a/app/models/wizards/signup/abo_basic_login_wizard.rb +++ b/app/models/wizards/signup/abo_basic_login_wizard.rb @@ -33,9 +33,8 @@ def save! def build_person if current_user.present? - person = current_user.tap do |person| - role = person.roles.build(group: group, type: group.self_registration_role_type) - yield person, role if block_given? + current_user.tap do |person| + person.roles.build(group: group, type: group.self_registration_role_type) end else super do |_person, role| From 6e89a7d445448ffad73d7bd743f33a2ed9a8deb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Tue, 17 Dec 2024 15:54:42 +0100 Subject: [PATCH 03/13] Add specs for current steps --- .../wizards/signup/abo_basic_login_wizard_spec.rb | 12 ++++++++++++ .../wizards/signup/abo_magazin_wizard_spec.rb | 14 ++++++++++++++ .../signup/abo_touren_portal_wizard_spec.rb | 12 ++++++++++++ 3 files changed, 38 insertions(+) diff --git a/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb b/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb index 15b2cb800..6c51657d7 100644 --- a/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb @@ -105,4 +105,16 @@ def build(params = required_attrs) expect(newsletter.people).to be_empty end end + + describe "steps" do + it "starts at main email field step when not logged in" do + expect(wizard.step_at(0)).to be_instance_of(Wizards::Steps::Signup::MainEmailField) + expect(wizard.step_at(1)).to be_instance_of(Wizards::Steps::Signup::AboBasicLogin::PersonFields) + end + + it "starts at person fields step when logged in" do + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:admin)) + expect(wizard.step_at(0)).to be_instance_of(Wizards::Steps::Signup::AboBasicLogin::PersonFields) + end + end end diff --git a/spec/models/wizards/signup/abo_magazin_wizard_spec.rb b/spec/models/wizards/signup/abo_magazin_wizard_spec.rb index aa216ad28..8e9cf68a8 100644 --- a/spec/models/wizards/signup/abo_magazin_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_magazin_wizard_spec.rb @@ -141,4 +141,18 @@ def build(params = required_attrs) expect(wizard.calculated_costs).to eq(76) end end + + describe "steps" do + it "starts at main email field step when not logged in" do + expect(wizard.step_at(0)).to be_instance_of(Wizards::Steps::Signup::MainEmailField) + expect(wizard.step_at(1)).to be_instance_of(Wizards::Steps::Signup::AboMagazin::PersonFields) + expect(wizard.step_at(2)).to be_instance_of(Wizards::Steps::Signup::AboMagazin::Summary) + end + + it "starts at person fields step when logged in" do + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:admin)) + expect(wizard.step_at(0)).to be_instance_of(Wizards::Steps::Signup::AboMagazin::PersonFields) + expect(wizard.step_at(1)).to be_instance_of(Wizards::Steps::Signup::AboMagazin::Summary) + end + end end diff --git a/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb b/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb index 2aad5a471..3d68d2113 100644 --- a/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb @@ -115,4 +115,16 @@ def build(params = required_attrs) expect(newsletter.people).to eq [max] end end + + describe "steps" do + it "starts at main email field step when not logged in" do + expect(wizard.step_at(0)).to be_instance_of(Wizards::Steps::Signup::MainEmailField) + expect(wizard.step_at(1)).to be_instance_of(Wizards::Steps::Signup::AboTourenPortal::PersonFields) + end + + it "starts at person fields step when logged in" do + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:admin)) + expect(wizard.step_at(0)).to be_instance_of(Wizards::Steps::Signup::AboTourenPortal::PersonFields) + end + end end From 80b8a583299f4010eacb9f0950ec40d1f95b627e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Tue, 17 Dec 2024 16:20:13 +0100 Subject: [PATCH 04/13] Add model spec for saving records --- spec/models/wizards/signup/abo_basic_login_wizard_spec.rb | 7 +++++++ spec/models/wizards/signup/abo_magazin_wizard_spec.rb | 7 +++++++ .../models/wizards/signup/abo_touren_portal_wizard_spec.rb | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb b/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb index 6c51657d7..0b4f81ba8 100644 --- a/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb @@ -104,6 +104,13 @@ def build(params = required_attrs) expect(max.subscriptions).to be_empty expect(newsletter.people).to be_empty end + + it "saves role for current_user when logged in" do + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:admin)) + expect(wizard).to be_valid + expect { wizard.save! }.not_to change { Person.count } + expect(people(:admin).roles.last.type).to eq Group::AboBasicLogin::BasicLogin.sti_name + end end describe "steps" do diff --git a/spec/models/wizards/signup/abo_magazin_wizard_spec.rb b/spec/models/wizards/signup/abo_magazin_wizard_spec.rb index 8e9cf68a8..449ddbf4c 100644 --- a/spec/models/wizards/signup/abo_magazin_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_magazin_wizard_spec.rb @@ -129,6 +129,13 @@ def build(params = required_attrs) .with(kind_of(Person), group, true) end end + + it "saves role for current_user when logged in" do + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:admin)) + expect(wizard).to be_valid + expect { wizard.save! }.not_to change { Person.count } + expect(people(:admin).roles.last.type).to eq Group::AboMagazin::Abonnent.sti_name + end end describe "#calculate_costs" do diff --git a/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb b/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb index 3d68d2113..663debad2 100644 --- a/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb @@ -114,6 +114,13 @@ def build(params = required_attrs) expect(max.subscriptions).to have(1).item expect(newsletter.people).to eq [max] end + + it "saves role for current_user when logged in" do + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:admin)) + expect(wizard).to be_valid + expect { wizard.save! }.not_to change { Person.count } + expect(people(:admin).roles.last.type).to eq Group::AboTourenPortal::Abonnent.sti_name + end end describe "steps" do From 2d5765d174812282f81b8cc0a8d04f6430064859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Tue, 17 Dec 2024 16:46:26 +0100 Subject: [PATCH 05/13] Add feature spec for all abo wizards --- spec/features/signup/abo_basic_login_spec.rb | 13 +++++++++++++ spec/features/signup/abo_magazin_spec.rb | 15 +++++++++++++++ spec/features/signup/abo_touren_portal_spec.rb | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/spec/features/signup/abo_basic_login_spec.rb b/spec/features/signup/abo_basic_login_spec.rb index 6ef7441af..c9516e0c7 100644 --- a/spec/features/signup/abo_basic_login_spec.rb +++ b/spec/features/signup/abo_basic_login_spec.rb @@ -102,4 +102,17 @@ def expect_validation_error(message) expect(page).to have_link("Anmelden") end end + + it "has prefilled form when logged in" do + people(:admin).update!(country: "CH") + sign_in(people(:admin)) + visit group_self_registration_path(group_id: group) + expect(page).to have_text "SAC-KONTO ERSTELLEN" + expect(page).not_to have_text "Weiter" + check "Ich habe die Datenschutzerklärung gelesen und stimme dieser zu" + expect do + click_button "SAC-KONTO ERSTELLEN" + expect(page).to have_css "#error_explanation, #flash > .alert" + end.to change { Role.count }.by(1) + end end diff --git a/spec/features/signup/abo_magazin_spec.rb b/spec/features/signup/abo_magazin_spec.rb index e7b9c1eca..e9ed13ef3 100644 --- a/spec/features/signup/abo_magazin_spec.rb +++ b/spec/features/signup/abo_magazin_spec.rb @@ -155,4 +155,19 @@ def complete_last_page(date: Date.tomorrow, submit: true) expect(page).to have_field("Geburtsdatum", with: "03.01.1924") end end + + it "has prefilled form when logged in" do + people(:admin).update!(country: "CH") + sign_in(people(:admin)) + visit group_self_registration_path(group_id: group) + expect_active_step "Personendaten" + click_button "Weiter" + expect(page).to have_text "support@hitobito.example.com" + check "Ich habe die AGB gelesen und stimme diesen zu" + check "Ich habe die Datenschutzerklärung gelesen und stimme dieser zu" + expect do + click_button "ABO KOSTENPFLICHTIG BESTELLEN" + expect(page).to have_css "#error_explanation, #flash > .alert" + end.to change { Role.count }.by(1) + end end diff --git a/spec/features/signup/abo_touren_portal_spec.rb b/spec/features/signup/abo_touren_portal_spec.rb index 65f5b86c0..ae8bf8f61 100644 --- a/spec/features/signup/abo_touren_portal_spec.rb +++ b/spec/features/signup/abo_touren_portal_spec.rb @@ -114,4 +114,18 @@ def expect_validation_error(message) expect(page).to have_text "Person muss 18 Jahre oder älter sein" end.not_to change { Person.count } end + + it "has prefilled form when logged in" do + people(:admin).update!(country: "CH") + sign_in(people(:admin)) + visit group_self_registration_path(group_id: group) + expect(page).to have_text "Registrieren" + expect(page).not_to have_text "Weiter" + check "Ich habe die Statuten gelesen und stimme diesen zu" + check "Ich habe die Datenschutzerklärung gelesen und stimme dieser zu" + expect do + click_button "Registrieren" + expect(page).to have_css "#error_explanation, #flash > .alert" + end.to change { Role.count }.by(1) + end end From 9e2cba19ee0d47704cef959ef912136c0b434556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Wed, 18 Dec 2024 14:19:54 +0100 Subject: [PATCH 06/13] Adjust views to not display unwanted info --- app/views/groups/self_registration/_aside_abo.html.haml | 3 ++- .../steps/signup/abo_magazin/_person_info_table.html.haml | 2 +- lib/hitobito_sac_cas/wagon.rb | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/groups/self_registration/_aside_abo.html.haml b/app/views/groups/self_registration/_aside_abo.html.haml index 6a4c4d639..ee3d912c2 100644 --- a/app/views/groups/self_registration/_aside_abo.html.haml +++ b/app/views/groups/self_registration/_aside_abo.html.haml @@ -4,4 +4,5 @@ = turbo_frame_tag(partial_name, class: 'col-md') do = render "abo_infos", costs: wizard.costs - = render(SelfRegistration::InfosComponent.new) + - unless current_user + = render(SelfRegistration::InfosComponent.new) diff --git a/app/views/wizards/steps/signup/abo_magazin/_person_info_table.html.haml b/app/views/wizards/steps/signup/abo_magazin/_person_info_table.html.haml index fbb9367f0..8547a0d8a 100644 --- a/app/views/wizards/steps/signup/abo_magazin/_person_info_table.html.haml +++ b/app/views/wizards/steps/signup/abo_magazin/_person_info_table.html.haml @@ -20,7 +20,7 @@ %td=person.last_name %tr %td=t("activemodel.attributes.wizards/steps/signup/main_email_field.email") - %td=person.email || wizard.main_email_field.email + %td=wizard.email %tr %td=person.class.human_attribute_name(:birthday) %td=person.birthday.strftime("%d.%m.%Y") diff --git a/lib/hitobito_sac_cas/wagon.rb b/lib/hitobito_sac_cas/wagon.rb index cab3b5e96..c9e7cd843 100644 --- a/lib/hitobito_sac_cas/wagon.rb +++ b/lib/hitobito_sac_cas/wagon.rb @@ -71,7 +71,6 @@ class Wagon < Rails::Engine QualificationKind.include SacCas::QualificationKind Contactable.prepend SacCas::Contactable Wizards::Steps::NewUserForm.support_company = false - Wizards::RegisterNewUserWizard.delegate :email, to: :new_user_form HouseholdAsideComponent.prepend SacCas::HouseholdAsideComponent HouseholdAsideMemberComponent.prepend SacCas::HouseholdAsideMemberComponent From fa031a7d6bd4fd297c6675ebcb3317e1ce0770ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Wed, 18 Dec 2024 14:20:37 +0100 Subject: [PATCH 07/13] Move member_or_applied? to wizards --- .../sac_cas/groups/self_registration_controller.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/controllers/sac_cas/groups/self_registration_controller.rb b/app/controllers/sac_cas/groups/self_registration_controller.rb index 39df3f85c..dc2ade7b3 100644 --- a/app/controllers/sac_cas/groups/self_registration_controller.rb +++ b/app/controllers/sac_cas/groups/self_registration_controller.rb @@ -18,7 +18,7 @@ module SacCas::Groups::SelfRegistrationController def restrict_access return redirect_to_login if !signed_in? && email_exists? - return redirect_to_memberships_tab if member_or_applied? + return redirect_to_memberships_tab if wizard.member_or_applied? redirect_to_person_show if family? end @@ -26,11 +26,6 @@ def email_exists? = email.present? && Person.exists?(email: email) def family? = current_user&.household&.present? - def member_or_applied? - current_user&.sac_membership&.stammsektion_role || - current_user&.sac_membership&.neuanmeldung_stammsektion_role - end - def model_class case group when Group::AboBasicLogin From f86b1ec807bd3c61ff1386f5effdaf4672e3141b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Wed, 18 Dec 2024 14:20:51 +0100 Subject: [PATCH 08/13] General cleanup --- .../wizards/signup/abo_basic_login_wizard.rb | 34 ++++++------------- .../wizards/signup/abo_magazin_wizard.rb | 10 ++++++ .../signup/abo_touren_portal_wizard.rb | 9 +++++ app/models/wizards/signup/sektion_wizard.rb | 5 +-- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/app/models/wizards/signup/abo_basic_login_wizard.rb b/app/models/wizards/signup/abo_basic_login_wizard.rb index 1ca624941..902c29f56 100644 --- a/app/models/wizards/signup/abo_basic_login_wizard.rb +++ b/app/models/wizards/signup/abo_basic_login_wizard.rb @@ -14,13 +14,16 @@ class AboBasicLoginWizard < Wizards::RegisterNewUserWizard public :group - delegate :email, to: :main_email_field delegate :newsletter, to: :person_fields self.asides = ["aside_abo_basic_login"] + def member_or_applied? + current_user.login? #do not allow if person already has a login + end + def save! - if current_user.present? + if current_user person.save! else super @@ -32,37 +35,20 @@ def save! private def build_person - if current_user.present? - current_user.tap do |person| - person.roles.build(group: group, type: group.self_registration_role_type) - end - else - super do |_person, role| - role.end_on = Date.current.end_of_year - end + super do |_person, role| + role.end_on = Date.current.end_of_year end end def person_attributes - person_fields - .person_attributes - .merge(main_email_field.attributes) + person_fields.person_attributes.merge(email:) end def step_after(step_class_or_name) - case step_class_or_name - when :_start - handle_start - else - super - end - end - - def handle_start - if current_user.present? + if step_class_or_name == :_start && current_user Wizards::Steps::Signup::AboBasicLogin::PersonFields.step_name else - Wizards::Steps::Signup::MainEmailField.step_name + super end end diff --git a/app/models/wizards/signup/abo_magazin_wizard.rb b/app/models/wizards/signup/abo_magazin_wizard.rb index 40624ea86..d1626c59f 100644 --- a/app/models/wizards/signup/abo_magazin_wizard.rb +++ b/app/models/wizards/signup/abo_magazin_wizard.rb @@ -15,8 +15,18 @@ class AboMagazinWizard < AboBasicLoginWizard self.asides = ["aside_abo"] + RESTRICTED_ROLES = [ + Group::AboMagazin::Abonnent.sti_name, + Group::AboMagazin::Neuanmeldung.sti_name, + Group::AboMagazin::Gratisabonnent.sti_name + ].freeze + delegate :newsletter, to: :summary + def member_or_applied? + current_user&.roles&.map(&:type)&.any? { |type| RESTRICTED_ROLES.include?(type) } + end + def costs = SacCas::ABO_COSTS[:magazin] def requires_policy_acceptance? = false diff --git a/app/models/wizards/signup/abo_touren_portal_wizard.rb b/app/models/wizards/signup/abo_touren_portal_wizard.rb index f5ab7ca67..80302151f 100644 --- a/app/models/wizards/signup/abo_touren_portal_wizard.rb +++ b/app/models/wizards/signup/abo_touren_portal_wizard.rb @@ -14,6 +14,15 @@ class AboTourenPortalWizard < AboBasicLoginWizard self.asides = ["aside_abo"] + RESTRICTED_ROLES = [ + Group::AboTourenPortal::Abonnent.sti_name, + Group::AboTourenPortal::Neuanmeldung.sti_name + ].freeze + + def member_or_applied? + current_user&.roles&.map(&:type)&.any? { |type| RESTRICTED_ROLES.include?(type) } + end + def costs = SacCas::ABO_COSTS[:tourenportal] end end diff --git a/app/models/wizards/signup/sektion_wizard.rb b/app/models/wizards/signup/sektion_wizard.rb index 2614d593d..acf772379 100644 --- a/app/models/wizards/signup/sektion_wizard.rb +++ b/app/models/wizards/signup/sektion_wizard.rb @@ -28,8 +28,9 @@ class SektionWizard < Wizards::RegisterNewUserWizard public :group - def email - current_user&.email || step(:main_email_field)&.email + def member_or_applied? + current_user&.sac_membership&.stammsektion_role || + current_user&.sac_membership&.neuanmeldung_stammsektion_role end def save! From 3dcc5b7e88b21e34e19b7075c4f69c4699a242c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Wed, 18 Dec 2024 16:21:49 +0100 Subject: [PATCH 09/13] Add spec to check if wizard is viewable --- .../signup/abo_basic_login_wizard_spec.rb | 15 ++++++++++++ .../wizards/signup/abo_magazin_wizard_spec.rb | 24 +++++++++++++++++++ .../signup/abo_touren_portal_wizard_spec.rb | 20 ++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb b/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb index 0b4f81ba8..fda33ae9d 100644 --- a/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb @@ -124,4 +124,19 @@ def build(params = required_attrs) expect(wizard.step_at(0)).to be_instance_of(Wizards::Steps::Signup::AboBasicLogin::PersonFields) end end + + describe "#member_or_applied?" do + before do + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:mitglied)) + end + + it "returns true when user has login" do + expect(wizard.member_or_applied?).to be_truthy + end + + it "returns true if user does not have login" do + allow(people(:admin)).to receive(:login?).and_return(false) + expect(wizard.member_or_applied?).to be_falsy + end + end end diff --git a/spec/models/wizards/signup/abo_magazin_wizard_spec.rb b/spec/models/wizards/signup/abo_magazin_wizard_spec.rb index 449ddbf4c..c976ea1e6 100644 --- a/spec/models/wizards/signup/abo_magazin_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_magazin_wizard_spec.rb @@ -162,4 +162,28 @@ def build(params = required_attrs) expect(wizard.step_at(1)).to be_instance_of(Wizards::Steps::Signup::AboMagazin::Summary) end end + + describe "#member_or_applied?" do + before do + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:mitglied)) + end + + it "returns true when user has abonnent role" do + expect(wizard.member_or_applied?).to be_truthy + end + + it "returns true when user has neuanmeldung role" do + Group::AboMagazin::Neuanmeldung.create!(person: people(:mitglied), group: groups(:abo_die_alpen)) + expect(wizard.member_or_applied?).to be_truthy + end + + it "returns true when user has gratis abonnent role" do + Group::AboMagazin::Gratisabonnent.create!(person: people(:mitglied), group: groups(:abo_die_alpen)) + expect(wizard.member_or_applied?).to be_truthy + end + + it "returns false if user does not have role" do + expect(wizard.member_or_applied?).to be_falsy + end + end end diff --git a/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb b/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb index 663debad2..a1a2c219d 100644 --- a/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb @@ -134,4 +134,24 @@ def build(params = required_attrs) expect(wizard.step_at(0)).to be_instance_of(Wizards::Steps::Signup::AboTourenPortal::PersonFields) end end + + describe "#member_or_applied?" do + before do + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:mitglied)) + end + + it "returns true when user has abonnent role" do + Group::AboTourenPortal::Abonnent.create!(person: people(:mitglied), group: group) + expect(wizard.member_or_applied?).to be_truthy + end + + it "returns true when user has neuanmeldung role" do + Group::AboTourenPortal::Neuanmeldung.create!(person: people(:mitglied), group: group) + expect(wizard.member_or_applied?).to be_truthy + end + + it "returns false if user does not have role" do + expect(wizard.member_or_applied?).to be_falsy + end + end end From d22e508dca1ebb7257b8053b46c6324ab2b673a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Wed, 18 Dec 2024 16:29:57 +0100 Subject: [PATCH 10/13] Fix rubocop --- app/models/wizards/signup/abo_basic_login_wizard.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/wizards/signup/abo_basic_login_wizard.rb b/app/models/wizards/signup/abo_basic_login_wizard.rb index 902c29f56..c23b2d042 100644 --- a/app/models/wizards/signup/abo_basic_login_wizard.rb +++ b/app/models/wizards/signup/abo_basic_login_wizard.rb @@ -19,7 +19,7 @@ class AboBasicLoginWizard < Wizards::RegisterNewUserWizard self.asides = ["aside_abo_basic_login"] def member_or_applied? - current_user.login? #do not allow if person already has a login + current_user&.login? # do not allow if person already has a login end def save! From 5cb3676afff033f2b82225daa0d26ee036d9aa4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Wed, 18 Dec 2024 16:38:44 +0100 Subject: [PATCH 11/13] Fix broken specs --- spec/models/wizards/signup/abo_basic_login_wizard_spec.rb | 2 +- spec/models/wizards/signup/abo_magazin_wizard_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb b/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb index fda33ae9d..dad51be30 100644 --- a/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_basic_login_wizard_spec.rb @@ -135,7 +135,7 @@ def build(params = required_attrs) end it "returns true if user does not have login" do - allow(people(:admin)).to receive(:login?).and_return(false) + allow(people(:mitglied)).to receive(:login?).and_return(false) expect(wizard.member_or_applied?).to be_falsy end end diff --git a/spec/models/wizards/signup/abo_magazin_wizard_spec.rb b/spec/models/wizards/signup/abo_magazin_wizard_spec.rb index c976ea1e6..d752c9a83 100644 --- a/spec/models/wizards/signup/abo_magazin_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_magazin_wizard_spec.rb @@ -169,6 +169,7 @@ def build(params = required_attrs) end it "returns true when user has abonnent role" do + Group::AboMagazin::Abonnent.create!(person: people(:mitglied), group: groups(:abo_die_alpen)) expect(wizard.member_or_applied?).to be_truthy end From 12b6dbe34da9ca8c5f810e75cca144a4e9dabed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Wed, 18 Dec 2024 17:31:01 +0100 Subject: [PATCH 12/13] Fix feature specs --- spec/features/signup/abo_basic_login_spec.rb | 11 ++--------- spec/features/signup/abo_magazin_spec.rb | 7 +++++++ spec/features/signup/abo_touren_portal_spec.rb | 7 +++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/spec/features/signup/abo_basic_login_spec.rb b/spec/features/signup/abo_basic_login_spec.rb index c9516e0c7..cb32335f0 100644 --- a/spec/features/signup/abo_basic_login_spec.rb +++ b/spec/features/signup/abo_basic_login_spec.rb @@ -103,16 +103,9 @@ def expect_validation_error(message) end end - it "has prefilled form when logged in" do - people(:admin).update!(country: "CH") + it "redirects if logged in" do sign_in(people(:admin)) visit group_self_registration_path(group_id: group) - expect(page).to have_text "SAC-KONTO ERSTELLEN" - expect(page).not_to have_text "Weiter" - check "Ich habe die Datenschutzerklärung gelesen und stimme dieser zu" - expect do - click_button "SAC-KONTO ERSTELLEN" - expect(page).to have_css "#error_explanation, #flash > .alert" - end.to change { Role.count }.by(1) + expect(page).to have_content("Du besitzt bereits eine SAC-Mitgliedschaft. Wenn du diese anpassen möchtest, kontaktiere bitte die SAC-Geschäftsstelle.") end end diff --git a/spec/features/signup/abo_magazin_spec.rb b/spec/features/signup/abo_magazin_spec.rb index e9ed13ef3..f72f3abba 100644 --- a/spec/features/signup/abo_magazin_spec.rb +++ b/spec/features/signup/abo_magazin_spec.rb @@ -170,4 +170,11 @@ def complete_last_page(date: Date.tomorrow, submit: true) expect(page).to have_css "#error_explanation, #flash > .alert" end.to change { Role.count }.by(1) end + + it "redirects if already abonnent of magazin" do + sign_in(people(:mitglied)) + Group::AboMagazin::Abonnent.create!(person: people(:mitglied), group: group) + visit group_self_registration_path(group_id: group) + expect(page).to have_content("Du besitzt bereits eine SAC-Mitgliedschaft. Wenn du diese anpassen möchtest, kontaktiere bitte die SAC-Geschäftsstelle.") + end end diff --git a/spec/features/signup/abo_touren_portal_spec.rb b/spec/features/signup/abo_touren_portal_spec.rb index ae8bf8f61..1f7e3fda8 100644 --- a/spec/features/signup/abo_touren_portal_spec.rb +++ b/spec/features/signup/abo_touren_portal_spec.rb @@ -128,4 +128,11 @@ def expect_validation_error(message) expect(page).to have_css "#error_explanation, #flash > .alert" end.to change { Role.count }.by(1) end + + it "redirects if already abonnent of touren portal" do + sign_in(people(:mitglied)) + Group::AboTourenPortal::Abonnent.create!(person: people(:mitglied), group: group) + visit group_self_registration_path(group_id: group) + expect(page).to have_content("Du besitzt bereits eine SAC-Mitgliedschaft. Wenn du diese anpassen möchtest, kontaktiere bitte die SAC-Geschäftsstelle.") + end end From 8051b6fd70ce4349cf84ba7ae7567f61f3785743 Mon Sep 17 00:00:00 2001 From: Andreas Maierhofer Date: Wed, 18 Dec 2024 18:10:25 +0100 Subject: [PATCH 13/13] Cleanup specs a bit --- spec/models/wizards/signup/abo_magazin_wizard_spec.rb | 11 +++++++---- .../wizards/signup/abo_touren_portal_wizard_spec.rb | 8 +++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/spec/models/wizards/signup/abo_magazin_wizard_spec.rb b/spec/models/wizards/signup/abo_magazin_wizard_spec.rb index d752c9a83..70ffc6f85 100644 --- a/spec/models/wizards/signup/abo_magazin_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_magazin_wizard_spec.rb @@ -164,22 +164,25 @@ def build(params = required_attrs) end describe "#member_or_applied?" do + let(:person) { people(:mitglied) } + let(:group) { groups(:abo_die_alpen) } + before do - allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:mitglied)) + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(person) end it "returns true when user has abonnent role" do - Group::AboMagazin::Abonnent.create!(person: people(:mitglied), group: groups(:abo_die_alpen)) + Group::AboMagazin::Abonnent.create!(person:, group:) expect(wizard.member_or_applied?).to be_truthy end it "returns true when user has neuanmeldung role" do - Group::AboMagazin::Neuanmeldung.create!(person: people(:mitglied), group: groups(:abo_die_alpen)) + Group::AboMagazin::Neuanmeldung.create!(person:, group:) expect(wizard.member_or_applied?).to be_truthy end it "returns true when user has gratis abonnent role" do - Group::AboMagazin::Gratisabonnent.create!(person: people(:mitglied), group: groups(:abo_die_alpen)) + Group::AboMagazin::Gratisabonnent.create!(person:, group:) expect(wizard.member_or_applied?).to be_truthy end diff --git a/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb b/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb index a1a2c219d..335f98393 100644 --- a/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb +++ b/spec/models/wizards/signup/abo_touren_portal_wizard_spec.rb @@ -136,17 +136,19 @@ def build(params = required_attrs) end describe "#member_or_applied?" do + let(:person) { people(:mitglied) } + before do - allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(people(:mitglied)) + allow_any_instance_of(Wizards::Signup::AboBasicLoginWizard).to receive(:current_user).and_return(person) end it "returns true when user has abonnent role" do - Group::AboTourenPortal::Abonnent.create!(person: people(:mitglied), group: group) + Group::AboTourenPortal::Abonnent.create!(person:, group:) expect(wizard.member_or_applied?).to be_truthy end it "returns true when user has neuanmeldung role" do - Group::AboTourenPortal::Neuanmeldung.create!(person: people(:mitglied), group: group) + Group::AboTourenPortal::Neuanmeldung.create!(person:, group:) expect(wizard.member_or_applied?).to be_truthy end