summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/models/members_notifications_shared_example.rb
blob: ef5cea3f2a5ca00dfadb0396ea2a43065496705e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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::MAINTAINER)
    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