2013-06-19 08:40:33 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
2014-10-09 11:22:20 -04:00
|
|
|
# Table name: members
|
2013-06-19 08:40:33 -04:00
|
|
|
#
|
2013-08-21 05:34:02 -04:00
|
|
|
# id :integer not null, primary key
|
2014-09-15 04:36:50 -04:00
|
|
|
# access_level :integer not null
|
2014-10-09 11:22:20 -04:00
|
|
|
# source_id :integer not null
|
|
|
|
# source_type :string(255) not null
|
2015-05-03 12:05:38 -04:00
|
|
|
# user_id :integer
|
2014-10-09 11:22:20 -04:00
|
|
|
# notification_level :integer not null
|
|
|
|
# type :string(255)
|
2014-04-09 08:05:03 -04:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2015-05-03 12:05:38 -04:00
|
|
|
# created_by_id :integer
|
|
|
|
# invite_email :string(255)
|
|
|
|
# invite_token :string(255)
|
|
|
|
# invite_accepted_at :datetime
|
2013-06-19 08:40:33 -04:00
|
|
|
#
|
|
|
|
|
2013-06-17 06:07:16 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 04:50:51 -05:00
|
|
|
describe GroupMember, models: true do
|
2014-06-17 14:36:40 -04:00
|
|
|
context 'notification' do
|
|
|
|
describe "#after_create" do
|
|
|
|
it "should send email to user" do
|
2014-09-15 04:36:50 -04:00
|
|
|
membership = build(:group_member)
|
2015-05-21 17:49:06 -04:00
|
|
|
|
|
|
|
allow(membership).to receive(:notification_service).
|
|
|
|
and_return(double('NotificationService').as_null_object)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(membership).to receive(:notification_service)
|
2015-05-21 17:49:06 -04:00
|
|
|
|
2014-06-17 14:36:40 -04:00
|
|
|
membership.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#after_update" do
|
|
|
|
before do
|
2015-03-13 11:16:51 -04:00
|
|
|
@group_member = create :group_member
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(@group_member).to receive(:notification_service).
|
|
|
|
and_return(double('NotificationService').as_null_object)
|
2014-06-17 14:36:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should send email to user" do
|
2015-03-13 11:16:51 -04:00
|
|
|
expect(@group_member).to receive(:notification_service)
|
|
|
|
@group_member.update_attribute(:access_level, GroupMember::MASTER)
|
2014-06-17 14:36:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not send an email when the access level has not changed" do
|
2015-03-13 11:16:51 -04:00
|
|
|
expect(@group_member).not_to receive(:notification_service)
|
|
|
|
@group_member.update_attribute(:access_level, GroupMember::OWNER)
|
2014-06-17 14:36:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-06-17 06:07:16 -04:00
|
|
|
end
|