Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send mail for everyone leaving the layer #179

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/jobs/alumni_mail_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2017, Pfadibewegung Schweiz. This file is part of
# Copyright (c) 2017-2024, Pfadibewegung Schweiz. This file is part of
# hitobito_jubla 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_jubla.
Expand All @@ -12,7 +12,7 @@ def initialize(group_id, person_id)
end

def perform
return if person.roles.without_alumnus.any?
return if no_more_active_roles?

if group.is_a?(Group::Flock)
AlumniMailer.new_member_flock(person).deliver_now
Expand All @@ -23,8 +23,12 @@ def perform

private

def no_more_active_roles?
person.roles.without_alumnus.roles_in_layer(person.id, group.layer_group_id).any?
end

def group
Group.find(@group_id)
@group ||= Group.find(@group_id)
end

def person
Expand Down
16 changes: 14 additions & 2 deletions spec/jobs/alumni_mail_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# encoding: utf-8

# Copyright (c) 2012-2017, Jungwacht Blauring Schweiz. This file is part of
# Copyright (c) 2012-2024, Jungwacht Blauring Schweiz. This file is part of
# hitobito_jubla 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_jubla.
Expand Down Expand Up @@ -35,14 +35,26 @@
expect { AlumniMailJob.new(group.id, person.id).perform }.to change { ActionMailer::Base.deliveries.size }.by(1)
end

it 'does not send email if there are other roles left' do
it 'does not send flock email if there are other roles in the current flock-layer left' do
group = groups(:bern)
person = Fabricate(Group::Flock::Leader.sti_name.to_sym, group: group).person

expect(AlumniMailer).not_to receive(:new_member_flock).and_call_original
expect(AlumniMailer).not_to receive(:new_member).and_call_original
expect { AlumniMailJob.new(group.id, person.id).perform }.to change { ActionMailer::Base.deliveries.size }.by(0)
end

it 'sends flock email if there are other roles in other layers' do
group = groups(:bern)
other_group = groups(:muri)

role_class = Group::Flock::Leader.sti_name.to_sym

person = Fabricate(role_class, group: other_group).person

expect(AlumniMailer).to receive(:new_member_flock).with(person).and_call_original
expect { AlumniMailJob.new(group.id, person.id).perform }.to change { ActionMailer::Base.deliveries.size }.by(1)
end
end

end
Loading