diff --git a/spec/models/memberships/switch_stammsektion_spec.rb b/spec/models/memberships/switch_stammsektion_spec.rb index 6a41196a7..890f0073e 100644 --- a/spec/models/memberships/switch_stammsektion_spec.rb +++ b/spec/models/memberships/switch_stammsektion_spec.rb @@ -50,6 +50,12 @@ def create_role(key, role, owner: person, **attrs) expect(switch).to be_valid end + it "is valid with membership in different section active since today" do + create_role(:matterhorn_mitglieder, "Mitglied", start_on: Time.zone.today) + expect(switch).to be_valid + expect(switch).to be_valid + end + describe "existing membership in tree" do describe "join section" do it "is invalid if person is join_section member" do @@ -110,6 +116,17 @@ def create_role(key, role, owner: person, **attrs) expect(person.primary_group).to eq matterhorn_mitglieder end + it "creates new role and destroys existing when start_on is today" do + bluemlisalp_mitglied.update_column(:start_on, Time.zone.today) + expect do + expect(switch.save).to eq true + end.not_to(change { person.reload.roles.count }) + expect { bluemlisalp_mitglied.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect(matterhorn_mitglied.start_on).to eq now.to_date + expect(matterhorn_mitglied.end_on).to eq now.end_of_year.to_date + expect(person.primary_group).to eq matterhorn_mitglieder + end + it "creates new role and destroys existing if not yet active" do bluemlisalp_mitglied.update_columns(created_at: 1.minute.ago) expect do