2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
RSpec.shared_examples 'members notifications' do |entity_type|
|
|
|
|
let(:notification_service) { double('NotificationService').as_null_object }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(member).to receive(:notification_service).and_return(notification_service)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#after_create" do
|
|
|
|
let(:member) { build(:"#{entity_type}_member") }
|
|
|
|
|
|
|
|
it "sends email to user" do
|
|
|
|
expect(notification_service).to receive(:"new_#{entity_type}_member").with(member)
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
member.save!
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#after_update" do
|
|
|
|
let(:member) { create(:"#{entity_type}_member", :developer) }
|
|
|
|
|
|
|
|
it "calls NotificationService.update_#{entity_type}_member" do
|
|
|
|
expect(notification_service).to receive(:"update_#{entity_type}_member").with(member)
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
member.update_attribute(:access_level, Member::MAINTAINER)
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "does not send an email when the access level has not changed" do
|
|
|
|
expect(notification_service).not_to receive(:"update_#{entity_type}_member")
|
|
|
|
|
|
|
|
member.touch
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#accept_request' do
|
|
|
|
let(:member) { create(:"#{entity_type}_member", :access_request) }
|
|
|
|
|
|
|
|
it "calls NotificationService.new_#{entity_type}_member" do
|
|
|
|
expect(notification_service).to receive(:"new_#{entity_type}_member").with(member)
|
|
|
|
|
|
|
|
member.accept_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#accept_invite!" do
|
|
|
|
let(:member) { create(:"#{entity_type}_member", :invited) }
|
|
|
|
|
|
|
|
it "calls NotificationService.accept_#{entity_type}_invite" do
|
|
|
|
expect(notification_service).to receive(:"accept_#{entity_type}_invite").with(member)
|
|
|
|
|
|
|
|
member.accept_invite!(build(:user))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#decline_invite!" do
|
|
|
|
let(:member) { create(:"#{entity_type}_member", :invited) }
|
|
|
|
|
|
|
|
it "calls NotificationService.decline_#{entity_type}_invite" do
|
|
|
|
expect(notification_service).to receive(:"decline_#{entity_type}_invite").with(member)
|
|
|
|
|
|
|
|
member.decline_invite!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|