Skip to content

Commit

Permalink
Only look at current layer for active roles
Browse files Browse the repository at this point in the history
  • Loading branch information
kronn committed Dec 11, 2024
1 parent 49f5a9a commit d6889b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 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 person.roles.without_alumnus.roles_in_layer(person.id, group.layer_group_id).any?

if group.is_a?(Group::Flock)
AlumniMailer.new_member_flock(person).deliver_now
Expand All @@ -24,7 +24,7 @@ def perform
private

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

0 comments on commit d6889b8

Please sign in to comment.