notification calls email notification
This commit is contained in:
parent
02ca5793bc
commit
ce470e74ee
4 changed files with 45 additions and 4 deletions
|
|
@ -30,8 +30,20 @@ class Notification
|
|||
:person_id => person.id,
|
||||
:user_id => user.id)
|
||||
n.socket_to_uid(user.id) if n
|
||||
n.email_the_user(object) unless user.disable_mail || !n
|
||||
n
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def email_the_user(object)
|
||||
case self.kind
|
||||
when "new_request"
|
||||
self.user.mail(Jobs::MailRequestReceived, self.user_id, self.person_id)
|
||||
when "request_accepted"
|
||||
self.user.mail(Jobs::MailRequestAcceptance, self.user_id, self.person_id)
|
||||
when "comment_on_post"
|
||||
self.user.mail(Jobs::MailCommentOnPost, self.user_id, self.person_id, object)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ module Diaspora
|
|||
elsif contact_request.from != self.person
|
||||
if contact_request.save!
|
||||
Rails.logger.info("event=contact_request status=received_new_request from=#{contact_request.from.diaspora_handle} to=#{self.diaspora_handle}")
|
||||
self.mail(Jobs::MailRequestReceived, self.id, contact_request.from.id)
|
||||
end
|
||||
else
|
||||
Rails.logger.info "event=contact_request status=abort from=#{contact_request.from.diaspora_handle} to=#{self.diaspora_handle} reason=self-love"
|
||||
|
|
@ -68,7 +67,6 @@ module Diaspora
|
|||
|
||||
received_request.destroy
|
||||
self.save
|
||||
self.mail(Jobs::MailRequestAcceptance, self.id, received_request.from.id)
|
||||
end
|
||||
|
||||
def disconnect(bad_contact)
|
||||
|
|
|
|||
|
|
@ -67,6 +67,37 @@ describe Notification do
|
|||
n.should_receive(:socket_to_uid).once
|
||||
Notification.notify(@user, request, @person)
|
||||
end
|
||||
|
||||
context 'emails the user' do
|
||||
it 'email with notifications enabled' do
|
||||
request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect)
|
||||
opts = {:target_id => request.id,
|
||||
:kind => request.notification_type(@user, @person),
|
||||
:person_id => @person.id,
|
||||
:user_id => @user.id}
|
||||
|
||||
n = Notification.create(opts)
|
||||
Notification.stub!(:create).and_return n
|
||||
|
||||
n.should_receive(:email_the_user).once
|
||||
Notification.notify(@user, request, @person)
|
||||
end
|
||||
|
||||
it 'does not email with emails disabled' do
|
||||
request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect)
|
||||
opts = {:target_id => request.id,
|
||||
:kind => request.notification_type(@user, @person),
|
||||
:person_id => @person.id,
|
||||
:user_id => @user.id}
|
||||
|
||||
n = Notification.create(opts)
|
||||
Notification.stub!(:create).and_return n
|
||||
|
||||
@user.disable_mail = true
|
||||
n.should_not_receive(:email_the_user)
|
||||
Notification.notify(@user, request, @person)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ describe Diaspora::UserModules::Connecting do
|
|||
|
||||
it 'enqueues a mail job' do
|
||||
Resque.should_receive(:enqueue).with(Jobs::MailRequestReceived, user.id, person.id)
|
||||
user.receive_contact_request(@r)
|
||||
user.receive_object(@r, person)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ describe Diaspora::UserModules::Connecting do
|
|||
end
|
||||
it 'enqueues a mail job' do
|
||||
Resque.should_receive(:enqueue).with(Jobs::MailRequestAcceptance, user.id, user2.person.id).once
|
||||
user.receive_request(@acceptance, user2.person)
|
||||
user.receive_object(@acceptance, user2.person)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue