Skip to content

Commit

Permalink
Add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
njaeggi committed Dec 31, 2024
1 parent 66e5203 commit f6020fc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/models/memberships/switch_stammsektion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f6020fc

Please sign in to comment.