BigW Consortium Gitlab

group_member_spec.rb 1.64 KB
Newer Older
Dmitriy Zaporozhets committed
1 2
# == Schema Information
#
Valery Sizov committed
3
# Table name: members
Dmitriy Zaporozhets committed
4
#
Dmitriy Zaporozhets committed
5
#  id                 :integer          not null, primary key
6
#  access_level       :integer          not null
Valery Sizov committed
7 8
#  source_id          :integer          not null
#  source_type        :string(255)      not null
Stan Hu committed
9
#  user_id            :integer
Valery Sizov committed
10 11
#  notification_level :integer          not null
#  type               :string(255)
Dmitriy Zaporozhets committed
12 13
#  created_at         :datetime
#  updated_at         :datetime
Stan Hu committed
14 15 16 17
#  created_by_id      :integer
#  invite_email       :string(255)
#  invite_token       :string(255)
#  invite_accepted_at :datetime
Dmitriy Zaporozhets committed
18 19
#

20 21
require 'spec_helper'

Douwe Maan committed
22
describe GroupMember, models: true do
23 24 25
  context 'notification' do
    describe "#after_create" do
      it "should send email to user" do
26
        membership = build(:group_member)
27 28 29

        allow(membership).to receive(:notification_service).
          and_return(double('NotificationService').as_null_object)
30
        expect(membership).to receive(:notification_service)
31

32 33 34 35 36 37
        membership.save
      end
    end

    describe "#after_update" do
      before do
38
        @group_member = create :group_member
39 40
        allow(@group_member).to receive(:notification_service).
          and_return(double('NotificationService').as_null_object)
41 42 43
      end

      it "should send email to user" do
44 45
        expect(@group_member).to receive(:notification_service)
        @group_member.update_attribute(:access_level, GroupMember::MASTER)
46 47 48
      end

      it "does not send an email when the access level has not changed" do
49 50
        expect(@group_member).not_to receive(:notification_service)
        @group_member.update_attribute(:access_level, GroupMember::OWNER)
51 52 53
      end
    end
  end
54
end