diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index fa9c8c6b1..d4b4876d0 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -352,10 +352,7 @@ module JamRuby def send_new_band_follower(follower, band) - notifications = [] - band.band_musicians.each.each do |bm| - notification = Notification.new notification.description = NotificationTypes::NEW_BAND_FOLLOWER notification.source_user_id = follower.id @@ -558,7 +555,7 @@ module JamRuby # remove anyone in the session and invited musicians friends_and_followers = friends_and_followers - music_session.unique_users - music_session.invited_musicians - notifications, online_ff, offline_ff = [], [], [] + online_ff, offline_ff = [], [], [] notification_msg = format_msg(NotificationTypes::MUSICIAN_SESSION_JOIN, {:user => user}) friends_and_followers.each do |ff| @@ -1064,7 +1061,10 @@ module JamRuby def send_band_recording_saved(recording) - notification_msg = format_msg(NotificationTypes::BAND_RECORDING_SAVED, {:band => recording.band}) + band = recording.band + notification_msg = format_msg(NotificationTypes::BAND_RECORDING_SAVED, {:band => band}) + + offline_ff = [] band.followers.each do |bf| follower = bf.user @@ -1087,13 +1087,14 @@ module JamRuby @@mq_router.publish_to_user(of.id, notification_msg) else - offline_followers << follower + offline_ff << follower end end # send email notifications offline_ff.each do |f| begin + puts "f.id = #{f.id}" UserMailer.band_recording_saved(f, notification_msg).deliver rescue => e @@log.error("Unable to send BAND_RECORDING_SAVED email to user #{f.email} #{e}") diff --git a/ruby/spec/jam_ruby/models/notification_spec.rb b/ruby/spec/jam_ruby/models/notification_spec.rb index 95e425938..f37f31145 100644 --- a/ruby/spec/jam_ruby/models/notification_spec.rb +++ b/ruby/spec/jam_ruby/models/notification_spec.rb @@ -195,51 +195,20 @@ describe Notification do end end - describe "send band session join" do - let(:follower) {FactoryGirl.create(:user)} - let(:sender) {FactoryGirl.create(:user)} - let(:band) {FactoryGirl.create(:band)} - - # it "sends email when user is offline and subscribes to emails" do - # band.followers << follower - # band.users << sender - - # calls = count_publish_to_user_calls - # Notification.send_band_session_join(session, band) - - # 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 - # follower.subscribe_email = false - # follower.save! - - # band.followers << follower - # band.users << sender - - # calls = count_publish_to_user_calls - # Notification.send_band_session_join(session, band) - - # UserMailer.deliveries.length.should == 0 - # calls[:count].should == 0 - # end - end - describe "send musician recording saved join" do let(:receiver) {FactoryGirl.create(:user)} let(:recording) {FactoryGirl.create(:recording)} - # it "sends email when user is offline and subscribes to emails" do - # FactoryGirl.create(:friendship, :user => receiver, :friend => recording.owner) - # FactoryGirl.create(:friendship, :user => recording.owner, :friend => receiver) + it "sends email when user is offline and subscribes to emails" do + FactoryGirl.create(:friendship, :user => receiver, :friend => recording.owner) + FactoryGirl.create(:friendship, :user => recording.owner, :friend => receiver) - # calls = count_publish_to_user_calls - # Notification.send_musician_recording_saved(recording) + calls = count_publish_to_user_calls + Notification.send_musician_recording_saved(recording) - # UserMailer.deliveries.length.should == 1 - # calls[:count].should == 0 - # end + 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 FactoryGirl.create(:friendship, :user => receiver, :friend => recording.owner) @@ -256,7 +225,96 @@ describe Notification do end end + describe "send band session join" do + let(:follower) {FactoryGirl.create(:user)} + let(:sender) {FactoryGirl.create(:user)} + let(:band) {FactoryGirl.create(:band)} + let(:session) {FactoryGirl.create(:music_session)} + + it "sends email when user is offline and subscribes to emails" do + session.creator = sender + session.save! + + f = Follow.new + f.user_id = follower.id + f.followable_id = band.id + f.followable_type = "JamRuby::Band" + f.save! + + calls = count_publish_to_user_calls + Notification.send_band_session_join(session, band) + + 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 + session.creator = sender + session.save! + + follower.subscribe_email = false + follower.save! + + f = Follow.new + f.user_id = follower.id + f.followable_id = band.id + f.followable_type = "JamRuby::Band" + f.save! + + band.users << sender + + calls = count_publish_to_user_calls + Notification.send_band_session_join(session, band) + + UserMailer.deliveries.length.should == 0 + calls[:count].should == 0 + end + end + describe "send band recording saved join" do + let(:follower) {FactoryGirl.create(:user)} + let(:band) {FactoryGirl.create(:band)} + let(:recording) {FactoryGirl.create(:recording)} + + it "sends email when user is offline and subscribes to emails" do + f = Follow.new + f.user_id = follower.id + f.followable_id = band.id + f.followable_type = "JamRuby::Band" + f.save! + + recording.band = band + recording.save! + + calls = count_publish_to_user_calls + Notification.send_band_recording_saved(recording) + + 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 + follower.subscribe_email = false + follower.save! + + f = Follow.new + f.user_id = follower.id + f.followable_id = band.id + f.followable_type = "JamRuby::Band" + f.save! + + recording.band = band + recording.save! + + follower.subscribe_email = false + follower.save! + + calls = count_publish_to_user_calls + Notification.send_band_recording_saved(recording) + + UserMailer.deliveries.length.should == 0 + calls[:count].should == 0 + end end describe "send band invitation" do