aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuc Donnet2018-03-28 08:11:33 +0200
committerGitHub2018-03-28 08:11:33 +0200
commit12d06ea23dc55ffbfe347fc5898f0f9c8a55b45f (patch)
tree77f6e60387c44342017e6c6126186ac2e19a24a3 /spec
parentd3ab2606ffd3dcb94a27d7b4e7c899f1238d3a53 (diff)
parentad9a73328828648bc927f711060f5ed90bfcf947 (diff)
downloadchouette-core-12d06ea23dc55ffbfe347fc5898f0f9c8a55b45f.tar.bz2
Merge pull request #398 from af83/6259-calendar-mailer
Refs #6259 Only send mails to users from same workgroup after create/…
Diffstat (limited to 'spec')
-rw-r--r--spec/models/calendar_observer_spec.rb28
1 files changed, 20 insertions, 8 deletions
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