From a567673d4302676e183d78447dc515cfc3e47d45 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] 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