diff options
Diffstat (limited to 'spec/support/shared_examples/models/members_notifications_shared_example.rb')
-rw-r--r-- | spec/support/shared_examples/models/members_notifications_shared_example.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/support/shared_examples/models/members_notifications_shared_example.rb b/spec/support/shared_examples/models/members_notifications_shared_example.rb new file mode 100644 index 00000000000..76611e54306 --- /dev/null +++ b/spec/support/shared_examples/models/members_notifications_shared_example.rb @@ -0,0 +1,63 @@ +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) + + member.save + 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) + + member.update_attribute(:access_level, Member::MASTER) + 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 |