BigW Consortium Gitlab

group_member_spec.rb 1.42 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
Dmitriy Zaporozhets committed
9
#  user_id            :integer          not null
Valery Sizov committed
10 11
#  notification_level :integer          not null
#  type               :string(255)
Dmitriy Zaporozhets committed
12 13
#  created_at         :datetime
#  updated_at         :datetime
Dmitriy Zaporozhets committed
14 15
#

16 17
require 'spec_helper'

18
describe GroupMember do
19 20 21
  context 'notification' do
    describe "#after_create" do
      it "should send email to user" do
22
        membership = build(:group_member)
23 24 25 26 27 28 29 30
        membership.stub(notification_service: double('NotificationService').as_null_object)
        membership.should_receive(:notification_service)
        membership.save
      end
    end

    describe "#after_update" do
      before do
31
        @membership = create :group_member
32 33 34 35 36
        @membership.stub(notification_service: double('NotificationService').as_null_object)
      end

      it "should send email to user" do
        @membership.should_receive(:notification_service)
37
        @membership.update_attribute(:access_level, GroupMember::MASTER)
38 39 40 41
      end

      it "does not send an email when the access level has not changed" do
        @membership.should_not_receive(:notification_service)
42
        @membership.update_attribute(:access_level, GroupMember::OWNER)
43 44 45
      end
    end
  end
46
end