group_member_spec.rb 1.56 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1 2
# == Schema Information
#
Valery Sizov's avatar
Valery Sizov committed
3
# Table name: members
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4
#
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
5
#  id                 :integer          not null, primary key
6
#  access_level       :integer          not null
Valery Sizov's avatar
Valery Sizov committed
7 8
#  source_id          :integer          not null
#  source_type        :string(255)      not null
Stan Hu's avatar
Stan Hu committed
9
#  user_id            :integer
Valery Sizov's avatar
Valery Sizov committed
10 11
#  notification_level :integer          not null
#  type               :string(255)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
12 13
#  created_at         :datetime
#  updated_at         :datetime
Stan Hu's avatar
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's avatar
Dmitriy Zaporozhets committed
18 19
#

20 21
require 'spec_helper'

22
describe GroupMember do
23 24 25
  context 'notification' do
    describe "#after_create" do
      it "should send email to user" do
26
        membership = build(:group_member)
27
        membership.stub(notification_service: double('NotificationService').as_null_object)
28
        expect(membership).to receive(:notification_service)
29 30 31 32 33 34
        membership.save
      end
    end

    describe "#after_update" do
      before do
35 36
        @group_member = create :group_member
        @group_member.stub(notification_service: double('NotificationService').as_null_object)
37 38 39
      end

      it "should send email to user" do
40 41
        expect(@group_member).to receive(:notification_service)
        @group_member.update_attribute(:access_level, GroupMember::MASTER)
42 43 44
      end

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