From ad9a73328828648bc927f711060f5ed90bfcf947 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 21 Mar 2018 06:32:03 -0700 Subject: Refs #6259 Only send mails to users from same workgroup after create/update of shared calendars --- spec/models/calendar_observer_spec.rb | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'spec') diff --git a/spec/models/calendar_observer_spec.rb b/spec/models/calendar_observer_spec.rb index 4fba02bef..dd7034af4 100644 --- a/spec/models/calendar_observer_spec.rb +++ b/spec/models/calendar_observer_spec.rb @@ -1,8 +1,13 @@ require 'rails_helper' RSpec.describe CalendarObserver, type: :observer do - let(:calendar) { create(:calendar, shared: true) } - let(:user) { create(:user, organisation: create(:organisation)) } + let(:workgroup_1) { create :workgroup } + let(:workgroup_2) { create :workgroup } + + let(:calendar) { create(:calendar, shared: true, workgroup_id: workgroup_1.id) } + + let(:user_1) { create(:user, organisation: create(:organisation, workbenches: [create(:workbench, workgroup_id: workgroup_1.id)] )) } + let(:user_2) { create(:user, organisation: create(:organisation, workbenches: [create(:workbench, workgroup_id: workgroup_2.id)] )) } context 'after_update' do it 'should observe calendar updates' do @@ -12,14 +17,21 @@ RSpec.describe CalendarObserver, type: :observer do it 'should schedule mailer on calendar update' do calendar.name = 'edited_name' - expect(MailerJob).to receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user.id] + expect(MailerJob).to receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user_1.id] calendar.save end it 'should not schedule mailer for none shared calendar on update' do calendar = create(:calendar, shared: false) calendar.name = 'edited_name' - expect(MailerJob).to_not receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user.id] + expect(MailerJob).to_not receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user_1.id] + calendar.save + end + + it "should only send mail to user from the same workgroup" do + calendar.name = 'edited_name' + expect(MailerJob).to receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user_1.id] + expect(MailerJob).to_not receive(:perform_later).with 'CalendarMailer', 'updated', [calendar.id, user_2.id] calendar.save end end @@ -31,13 +43,13 @@ RSpec.describe CalendarObserver, type: :observer do end it 'should schedule mailer on calendar create' do - expect(MailerJob).to receive(:perform_later).with 'CalendarMailer', 'created', [anything, user.id] - build(:calendar, shared: true).save + expect(MailerJob).to receive(:perform_later).with 'CalendarMailer', 'created', [anything, user_1.id] + build(:calendar, shared: true, workgroup_id: workgroup_1.id).save end it 'should not schedule mailer for none shared calendar on create' do - expect(MailerJob).to_not receive(:perform_later).with 'CalendarMailer', 'created', [anything, user.id] - build(:calendar, shared: false).save + expect(MailerJob).to_not receive(:perform_later).with 'CalendarMailer', 'created', [anything, user_1.id] + build(:calendar, shared: false, workgroup_id: workgroup_1.id).save end end end -- cgit v1.2.3