2014-03-20 11:53:26 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe Notification do
|
|
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
|
UserMailer.deliveries.clear
|
2014-09-12 01:27:41 +00:00
|
|
|
MusicSession.delete_all
|
|
|
|
|
Recording.delete_all
|
|
|
|
|
Band.delete_all
|
|
|
|
|
BandInvitation.delete_all
|
|
|
|
|
Friendship.delete_all
|
|
|
|
|
Follow.delete_all
|
|
|
|
|
User.delete_all
|
|
|
|
|
|
|
|
|
|
@receiver = FactoryGirl.create(:user)
|
|
|
|
|
@sender = FactoryGirl.create(:user)
|
|
|
|
|
@recording = FactoryGirl.create(:recording)
|
|
|
|
|
@session = FactoryGirl.create(:music_session)
|
|
|
|
|
@band = FactoryGirl.create(:band)
|
|
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
@slot1 = FactoryGirl.build(:rsvp_slot, :music_session => @session, :instrument => JamRuby::Instrument.find('electric guitar'))
|
|
|
|
|
@slot1.save
|
|
|
|
|
|
|
|
|
|
@slot2 = FactoryGirl.build(:rsvp_slot, :music_session => @session, :instrument => JamRuby::Instrument.find('drums'))
|
|
|
|
|
@slot2.save
|
|
|
|
|
|
|
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@friend_request = FactoryGirl.create(:friend_request, user: @sender, friend: @receiver)
|
2014-03-20 11:53:26 +00:00
|
|
|
end
|
|
|
|
|
|
2014-03-25 15:29:08 +00:00
|
|
|
def count_publish_to_user_calls
|
|
|
|
|
result = {count: 0}
|
|
|
|
|
MQRouter.any_instance.stub(:publish_to_user) do |receiver_id, msg|
|
|
|
|
|
result[:count] += 1
|
|
|
|
|
result[:msg] = msg
|
|
|
|
|
end
|
|
|
|
|
result
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "send friend request" do
|
2014-09-10 07:04:35 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-03-25 15:29:08 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_friend_request(@friend_request.id, @sender.id, @receiver.id)
|
2014-03-25 15:29:08 +00:00
|
|
|
|
|
|
|
|
notification.errors.any?.should be_false
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_friend_request(@friend_request.id, @sender.id, @receiver.id)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
notification.errors.any?.should be_false
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
2014-03-25 15:29:08 +00:00
|
|
|
|
|
|
|
|
it "success when online" do
|
2014-09-12 01:27:41 +00:00
|
|
|
receiver_connection = FactoryGirl.create(:connection, user: @receiver)
|
2014-03-25 15:29:08 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_friend_request(@friend_request.id, @sender.id, @receiver.id)
|
2014-03-25 15:29:08 +00:00
|
|
|
|
|
|
|
|
notification.errors.any?.should be_false
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
describe "send friend request accepted" do
|
|
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-03-25 15:29:08 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_friend_request_accepted(@receiver.id, @sender.id)
|
2014-03-20 11:53:26 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
2014-03-25 15:29:08 +00:00
|
|
|
calls[:count].should == 0
|
2014-03-20 11:53:26 +00:00
|
|
|
end
|
|
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
2014-03-20 11:53:26 +00:00
|
|
|
|
2014-03-25 15:29:08 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_friend_request_accepted(@receiver.id, @sender.id)
|
2014-03-20 11:53:26 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-09-10 07:04:35 +00:00
|
|
|
calls[:count].should == 0
|
2014-03-20 11:53:26 +00:00
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
end
|
2014-03-20 11:53:26 +00:00
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
describe "send new user follower" do
|
|
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-03-25 15:29:08 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_new_user_follower(@sender, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_new_user_follower(@sender, @receiver)
|
2014-03-20 11:53:26 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-09-10 07:04:35 +00:00
|
|
|
calls[:count].should == 0
|
2014-03-20 11:53:26 +00:00
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
end
|
2014-03-20 11:53:26 +00:00
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
describe "send new band follower" do
|
|
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@band.users << @receiver
|
|
|
|
|
|
2014-03-25 15:29:08 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_new_band_follower(@sender, @band)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@band.users << @receiver
|
|
|
|
|
|
|
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_new_band_follower(@sender, @band)
|
2014-03-20 11:53:26 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-03-25 15:29:08 +00:00
|
|
|
calls[:count].should == 0
|
2014-03-20 11:53:26 +00:00
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
end
|
2014-03-20 11:53:26 +00:00
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
describe "send session invitation" do
|
|
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-03-25 15:29:08 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_session_invitation(@receiver, @sender, @session.id)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_session_invitation(@receiver, @sender, @session.id)
|
2014-03-20 11:53:26 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-03-25 15:29:08 +00:00
|
|
|
calls[:count].should == 0
|
2014-03-20 11:53:26 +00:00
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "send musician session join" do
|
|
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
FactoryGirl.create(:friendship, :user => @receiver, :friend => @sender)
|
|
|
|
|
FactoryGirl.create(:friendship, :user => @sender, :friend => @receiver)
|
2014-03-20 11:53:26 +00:00
|
|
|
|
2014-03-25 15:29:08 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_musician_session_join(@session, @sender)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-10-09 00:27:28 +00:00
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-09-10 07:04:35 +00:00
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
FactoryGirl.create(:friendship, :user => @receiver, :friend => @sender)
|
|
|
|
|
FactoryGirl.create(:friendship, :user => @sender, :friend => @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_musician_session_join(@session, @sender)
|
2014-03-20 11:53:26 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-03-25 15:29:08 +00:00
|
|
|
calls[:count].should == 0
|
2014-03-20 11:53:26 +00:00
|
|
|
end
|
|
|
|
|
end
|
2014-05-18 18:59:57 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
describe "send musician recording saved" do
|
2014-09-11 13:03:32 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
FactoryGirl.create(:friendship, :user => @receiver, :friend => @recording.owner)
|
|
|
|
|
FactoryGirl.create(:friendship, :user => @recording.owner, :friend => @receiver)
|
2014-09-11 13:03:32 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_musician_recording_saved(@recording)
|
2014-09-11 13:03:32 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
FactoryGirl.create(:friendship, :user => @receiver, :friend => @recording.owner)
|
|
|
|
|
FactoryGirl.create(:friendship, :user => @recording.owner, :friend => @receiver)
|
2015-07-10 15:51:12 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
2014-09-11 13:03:32 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_musician_recording_saved(@recording)
|
2014-09-11 13:03:32 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
describe "send band session join" do
|
|
|
|
|
let(:follower) {FactoryGirl.create(:user)}
|
|
|
|
|
|
2014-09-11 13:03:32 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-11 13:03:32 +00:00
|
|
|
f = Follow.new
|
|
|
|
|
f.user_id = follower.id
|
2014-09-12 01:27:41 +00:00
|
|
|
f.followable_id = @band.id
|
2014-09-11 13:03:32 +00:00
|
|
|
f.followable_type = "JamRuby::Band"
|
|
|
|
|
f.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-11 13:03:32 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_band_session_join(@session, @band)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-11 13:03:32 +00:00
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-11 13:03:32 +00:00
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-11 13:03:32 +00:00
|
|
|
|
|
|
|
|
follower.subscribe_email = false
|
|
|
|
|
follower.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-11 13:03:32 +00:00
|
|
|
f = Follow.new
|
|
|
|
|
f.user_id = follower.id
|
2014-09-12 01:27:41 +00:00
|
|
|
f.followable_id = @band.id
|
2014-09-11 13:03:32 +00:00
|
|
|
f.followable_type = "JamRuby::Band"
|
|
|
|
|
f.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-11 13:03:32 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_band_session_join(@session, @band)
|
2014-09-11 13:03:32 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
end
|
|
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
describe "send band recording saved" do
|
2014-09-11 13:03:32 +00:00
|
|
|
let(:follower) {FactoryGirl.create(:user)}
|
2014-09-11 12:38:26 +00:00
|
|
|
|
2014-09-11 13:03:32 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
|
|
|
|
f = Follow.new
|
|
|
|
|
f.user_id = follower.id
|
2014-09-12 01:27:41 +00:00
|
|
|
f.followable_id = @band.id
|
2014-09-11 13:03:32 +00:00
|
|
|
f.followable_type = "JamRuby::Band"
|
|
|
|
|
f.save!
|
2014-09-11 12:38:26 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@recording.band = @band
|
|
|
|
|
@recording.save!
|
2014-09-11 12:38:26 +00:00
|
|
|
|
2014-09-11 13:03:32 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_band_recording_saved(@recording)
|
2014-09-11 13:03:32 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
2014-09-11 12:38:26 +00:00
|
|
|
|
|
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-11 13:03:32 +00:00
|
|
|
follower.subscribe_email = false
|
|
|
|
|
follower.save!
|
|
|
|
|
|
|
|
|
|
f = Follow.new
|
|
|
|
|
f.user_id = follower.id
|
2014-09-12 01:27:41 +00:00
|
|
|
f.followable_id = @band.id
|
2014-09-11 13:03:32 +00:00
|
|
|
f.followable_type = "JamRuby::Band"
|
|
|
|
|
f.save!
|
|
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@recording.band = @band
|
|
|
|
|
@recording.save!
|
2015-07-10 15:51:12 +00:00
|
|
|
|
2014-09-11 13:03:32 +00:00
|
|
|
follower.subscribe_email = false
|
|
|
|
|
follower.save!
|
2014-09-11 12:38:26 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
Notification.send_band_recording_saved(@recording)
|
2014-09-11 12:38:26 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "send band invitation" do
|
2014-09-12 01:27:41 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
|
|
|
|
band_invitation = BandInvitation.new
|
|
|
|
|
band_invitation.receiver = @receiver
|
|
|
|
|
band_invitation.sender = @sender
|
|
|
|
|
band_invitation.band = @band
|
|
|
|
|
band_invitation.save!
|
|
|
|
|
|
|
|
|
|
@band.users << @sender
|
|
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
|
|
|
|
notification = Notification.send_band_invitation(@band, band_invitation, @sender, @receiver)
|
|
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
|
|
|
|
band_invitation = BandInvitation.new
|
|
|
|
|
band_invitation.receiver = @receiver
|
|
|
|
|
band_invitation.sender = @sender
|
|
|
|
|
band_invitation.band = @band
|
|
|
|
|
band_invitation.save!
|
|
|
|
|
|
|
|
|
|
@band.users << @sender
|
|
|
|
|
|
|
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
|
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
|
|
|
|
notification = Notification.send_band_invitation(@band, band_invitation, @sender, @receiver)
|
|
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "send band invitation accepted" do
|
2014-09-12 01:27:41 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
|
|
|
|
band_invitation = BandInvitation.new
|
|
|
|
|
band_invitation.receiver = @receiver
|
|
|
|
|
band_invitation.sender = @sender
|
|
|
|
|
band_invitation.band = @band
|
|
|
|
|
band_invitation.save!
|
|
|
|
|
|
|
|
|
|
@band.users << @sender
|
|
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
|
|
|
|
notification = Notification.send_band_invitation_accepted(@band, band_invitation, @receiver, @sender)
|
|
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
|
|
|
|
band_invitation = BandInvitation.new
|
|
|
|
|
band_invitation.receiver = @receiver
|
|
|
|
|
band_invitation.sender = @sender
|
|
|
|
|
band_invitation.band = @band
|
|
|
|
|
band_invitation.save!
|
|
|
|
|
|
|
|
|
|
@band.users << @sender
|
|
|
|
|
|
|
|
|
|
@sender.subscribe_email = false
|
|
|
|
|
@sender.save!
|
|
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
|
|
|
|
notification = Notification.send_band_invitation_accepted(@band, band_invitation, @receiver, @sender)
|
|
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
end
|
|
|
|
|
|
2014-05-18 18:59:57 +00:00
|
|
|
describe "send scheduled session invitation" do
|
2014-09-10 07:04:35 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_invitation(@session, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:count].should == 0
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
|
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_invitation(@session, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:count].should == 0
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if session is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_invitation(nil, @sender)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if user is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_invitation(@session, nil)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "send scheduled session rsvp" do
|
2014-09-10 07:04:35 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp(@session, @receiver, nil)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:count].should == 0
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
|
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator.subscribe_email = false
|
|
|
|
|
@session.creator.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp(@session, @receiver, nil)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:count].should == 0
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if session is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp(nil, @receiver, nil)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if user is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp(@session, nil, nil)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "send scheduled session rsvp approved" do
|
2014-09-10 07:04:35 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_approved(@session, @receiver, nil)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:count].should == 0
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
|
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_approved(@session, @receiver, nil)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:count].should == 0
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if session is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_approved(nil, @receiver, nil)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if user is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_approved(@session, nil, nil)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "send scheduled session rsvp cancellation" do
|
2014-09-10 07:04:35 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_cancelled(@session, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:count].should == 0
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
|
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator.subscribe_email = false
|
|
|
|
|
@session.creator.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_cancelled(@session, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:count].should == 0
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-05-18 18:59:57 +00:00
|
|
|
it "sends no notification if session is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_cancelled(nil, @receiver)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if user is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_cancelled(@session, nil)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "send scheduled session rsvp cancellation by organizer" do
|
2014-09-10 07:04:35 +00:00
|
|
|
it "sends email when user is offline and subscribes to emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_cancelled_org(@session, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:count].should == 0
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
|
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
it "does not send email when user is offline and opts out of emails" do
|
2014-09-12 01:27:41 +00:00
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2014-09-12 01:27:41 +00:00
|
|
|
@receiver.subscribe_email = false
|
|
|
|
|
@receiver.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_cancelled_org(@session, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:count].should == 0
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if session is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_cancelled_org(nil, @receiver)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if user is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rsvp_cancelled_org(@session, nil)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "send scheduled session cancellation" do
|
2014-09-10 07:04:35 +00:00
|
|
|
# it "sends email when user is offline and subscribes to emails" do
|
|
|
|
|
# session.creator = sender
|
|
|
|
|
# session.save!
|
|
|
|
|
|
|
|
|
|
# calls = count_publish_to_user_calls
|
|
|
|
|
# notification = Notification.send_scheduled_session_cancelled(session)
|
|
|
|
|
|
|
|
|
|
# UserMailer.deliveries.length.should == 1
|
|
|
|
|
# calls[:count].should == 1
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
# it "does not send email when user is offline and opts out of emails" do
|
|
|
|
|
# session.creator = sender
|
|
|
|
|
# session.save!
|
|
|
|
|
|
|
|
|
|
# receiver.subscribe_email = false
|
|
|
|
|
# receiver.save!
|
|
|
|
|
|
|
|
|
|
# calls = count_publish_to_user_calls
|
|
|
|
|
# notification = Notification.send_scheduled_session_cancelled(session)
|
|
|
|
|
|
|
|
|
|
# UserMailer.deliveries.length.should == 0
|
|
|
|
|
# calls[:count].should == 1
|
|
|
|
|
# end
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
it "sends no notification if session is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
|
|
|
|
notification = Notification.send_scheduled_session_cancelled(nil)
|
|
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if there are no rsvp requests" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_cancelled(@session)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "send scheduled session rescheduled" do
|
2014-09-10 07:04:35 +00:00
|
|
|
# it "sends email when user is offline and subscribes to emails" do
|
|
|
|
|
# session.creator = sender
|
|
|
|
|
# session.save!
|
|
|
|
|
|
|
|
|
|
# calls = count_publish_to_user_calls
|
|
|
|
|
# notification = Notification.send_scheduled_session_cancelled(session)
|
|
|
|
|
|
|
|
|
|
# UserMailer.deliveries.length.should == 1
|
|
|
|
|
# calls[:count].should == 1
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
# it "does not send email when user is offline and opts out of emails" do
|
|
|
|
|
# session.creator = sender
|
|
|
|
|
# session.save!
|
|
|
|
|
|
|
|
|
|
# receiver.subscribe_email = false
|
|
|
|
|
# receiver.save!
|
|
|
|
|
|
|
|
|
|
# calls = count_publish_to_user_calls
|
|
|
|
|
# notification = Notification.send_scheduled_session_cancelled(session)
|
|
|
|
|
|
|
|
|
|
# UserMailer.deliveries.length.should == 0
|
|
|
|
|
# calls[:count].should == 1
|
|
|
|
|
# end
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
it "sends no notification if session is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
|
|
|
|
notification = Notification.send_scheduled_session_rescheduled(nil)
|
|
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if there are no rsvp requests" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_rescheduled(@session)
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
describe "reminders" do
|
|
|
|
|
let(:mail) { UserMailer.deliveries[0] }
|
|
|
|
|
before :each do
|
|
|
|
|
UserMailer.deliveries.clear
|
|
|
|
|
end
|
|
|
|
|
it "sends no notification if session is nil" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
|
|
|
|
notification = Notification.send_session_reminders()
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
it "sends no notification if there are no rsvp requests" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
|
|
|
|
notification = Notification.send_session_reminders()
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
it "sends email 24 hours before" do
|
|
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.scheduled_start = Time.now + 23.hours
|
|
|
|
|
@session.save!
|
2014-09-10 07:04:35 +00:00
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
notification = Notification.send_session_reminders()
|
2014-05-18 18:59:57 +00:00
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
UserMailer.deliveries.length.should == 1
|
2014-05-18 18:59:57 +00:00
|
|
|
calls = count_publish_to_user_calls
|
|
|
|
|
calls[:count].should == 0
|
2015-07-10 15:51:12 +00:00
|
|
|
|
|
|
|
|
mail.html_part.body.include?("is scheduled for tomorrow").should be_true
|
|
|
|
|
mail.text_part.body.include?("is scheduled for tomorrow").should be_true
|
|
|
|
|
|
|
|
|
|
mail.html_part.body.include?("starts in 1 hour").should be_false
|
|
|
|
|
mail.text_part.body.include?("starts in 1 hour").should be_false
|
2014-05-18 18:59:57 +00:00
|
|
|
end
|
|
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
it "sends email 1 hour before" do
|
|
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.scheduled_start = Time.now + 59.minutes
|
|
|
|
|
@session.save!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notification = Notification.send_session_reminders()
|
|
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
2014-05-18 18:59:57 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2015-07-10 15:51:12 +00:00
|
|
|
calls[:count].should == 0
|
|
|
|
|
mail.html_part.body.include?("is scheduled for tomorrow").should be_false
|
|
|
|
|
mail.text_part.body.include?("is scheduled for tomorrow").should be_false
|
|
|
|
|
|
|
|
|
|
mail.html_part.body.include?("starts in 1 hour").should be_true
|
|
|
|
|
mail.text_part.body.include?("starts in 1 hour").should be_true
|
2014-05-18 18:59:57 +00:00
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends notice 5 minutes before" do
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
receiver_connection = FactoryGirl.create(:connection, user: @receiver)
|
|
|
|
|
@receiver.reload
|
|
|
|
|
|
|
|
|
|
rsvp = RsvpRequest.create({:session_id => @session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "We be jammin!"}, @receiver)
|
|
|
|
|
UserMailer.deliveries.clear
|
|
|
|
|
calls = count_publish_to_user_calls
|
|
|
|
|
@session.creator = @sender
|
|
|
|
|
@session.scheduled_start = Time.now + 4.minutes
|
|
|
|
|
@session.save!
|
|
|
|
|
notification = Notification.send_session_reminders()
|
|
|
|
|
calls[:count].should == 1
|
2014-05-18 18:59:57 +00:00
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
end
|
2015-07-10 15:51:12 +00:00
|
|
|
end # reminders
|
2014-05-18 18:59:57 +00:00
|
|
|
|
2014-09-10 07:04:35 +00:00
|
|
|
describe "send scheduled session comment" do
|
|
|
|
|
# it "sends email when user is offline and subscribes to emails" do
|
|
|
|
|
# session.creator = sender
|
|
|
|
|
# session.save!
|
|
|
|
|
|
|
|
|
|
# calls = count_publish_to_user_calls
|
|
|
|
|
# notification = Notification.send_scheduled_session_cancelled(session)
|
|
|
|
|
|
|
|
|
|
# UserMailer.deliveries.length.should == 1
|
|
|
|
|
# calls[:count].should == 1
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
# it "does not send email when user is offline and opts out of emails" do
|
|
|
|
|
# session.creator = sender
|
|
|
|
|
# session.save!
|
|
|
|
|
|
|
|
|
|
# receiver.subscribe_email = false
|
|
|
|
|
# receiver.save!
|
|
|
|
|
|
|
|
|
|
# calls = count_publish_to_user_calls
|
|
|
|
|
# notification = Notification.send_scheduled_session_cancelled(session)
|
|
|
|
|
|
|
|
|
|
# UserMailer.deliveries.length.should == 0
|
|
|
|
|
# calls[:count].should == 1
|
|
|
|
|
# end
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
it "sends no notification if session is nil" do
|
2014-05-22 04:40:17 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_comment(nil, @sender, 'when are we playing?')
|
2014-05-22 04:40:17 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if user is nil" do
|
2014-05-18 18:59:57 +00:00
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_comment(@session, nil, 'test')
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "sends no notification if comment is empty" do
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_scheduled_session_comment(@session, @sender, '')
|
2014-05-18 18:59:57 +00:00
|
|
|
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
describe "send_text_message" do
|
|
|
|
|
it "success when offline" do
|
|
|
|
|
message = "Just a test message!"
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_text_message(message, @sender, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
notification.errors.any?.should be_false
|
|
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "success when online" do
|
2014-09-12 01:27:41 +00:00
|
|
|
receiver_connection = FactoryGirl.create(:connection, user: @receiver)
|
2014-12-07 22:04:10 +00:00
|
|
|
@receiver.reload
|
2014-09-10 07:04:35 +00:00
|
|
|
message = "Just a test message!"
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_text_message(message, @sender, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
notification.errors.any?.should be_false
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 1
|
|
|
|
|
calls[:msg].text_message.msg.should == message
|
|
|
|
|
calls[:msg].text_message.photo_url.should == ''
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:msg].text_message.sender_name.should == @sender.name
|
2014-09-10 07:04:35 +00:00
|
|
|
calls[:msg].text_message.notification_id.should == notification.id
|
|
|
|
|
calls[:msg].text_message.created_at = notification.created_date
|
|
|
|
|
calls[:msg].text_message.clipped_msg.should be_false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "success when online with long message" do
|
2014-09-12 01:27:41 +00:00
|
|
|
receiver_connection = FactoryGirl.create(:connection, user: @receiver)
|
2014-12-07 22:04:10 +00:00
|
|
|
@receiver.reload
|
2014-09-10 07:04:35 +00:00
|
|
|
message = "0" * 203 # 200 is clip size
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_text_message(message, @sender, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
notification.errors.any?.should be_false
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 1
|
|
|
|
|
calls[:msg].text_message.msg.should == "0" * 200
|
|
|
|
|
calls[:msg].text_message.photo_url.should == ''
|
2014-09-12 01:27:41 +00:00
|
|
|
calls[:msg].text_message.sender_name.should == @sender.name
|
2014-09-10 07:04:35 +00:00
|
|
|
calls[:msg].text_message.notification_id.should == notification.id
|
|
|
|
|
calls[:msg].text_message.created_at = notification.created_date
|
|
|
|
|
calls[:msg].text_message.clipped_msg.should be_true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "fails with profanity" do
|
|
|
|
|
message = "ass"
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_text_message(message, @sender, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
notification.errors.any?.should be_true
|
|
|
|
|
notification.errors[:message].should == ['cannot contain profanity']
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "fails when target is same as receiver" do
|
|
|
|
|
message = "yo"
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_text_message(message, @sender, @sender)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
notification.errors.any?.should be_true
|
|
|
|
|
notification.errors[:target_user].should == [ValidationMessages::DIFFERENT_SOURCE_TARGET]
|
|
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "fails when there is no message" do
|
|
|
|
|
message = ''
|
|
|
|
|
calls = count_publish_to_user_calls
|
2014-09-12 01:27:41 +00:00
|
|
|
notification = Notification.send_text_message(message, @sender, @receiver)
|
2014-09-10 07:04:35 +00:00
|
|
|
|
|
|
|
|
notification.errors.any?.should be_true
|
2016-07-17 15:16:27 +00:00
|
|
|
notification.errors[:message].should == ['is too short (minimum is 1 character)']
|
2014-09-10 07:04:35 +00:00
|
|
|
UserMailer.deliveries.length.should == 0
|
|
|
|
|
calls[:count].should == 0
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-03-20 11:53:26 +00:00
|
|
|
end
|