placed all mail jobs in the Job::Mail:: namespace & added into appropriate folders
This commit is contained in:
parent
1e7a2f327b
commit
b6c26611ef
26 changed files with 112 additions and 100 deletions
11
app/models/jobs/mail/also_commented.rb
Normal file
11
app/models/jobs/mail/also_commented.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module Job
|
||||
module Mail
|
||||
class AlsoCommented < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, sender_id, comment_id)
|
||||
Notifier.also_commented(recipient_id, sender_id, comment_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
11
app/models/jobs/mail/comment_on_post.rb
Normal file
11
app/models/jobs/mail/comment_on_post.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module Job
|
||||
module Mail
|
||||
class CommentOnPost < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, sender_id, comment_id)
|
||||
Notifier.comment_on_post(recipient_id, sender_id, comment_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
10
app/models/jobs/mail/confirm_email.rb
Normal file
10
app/models/jobs/mail/confirm_email.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
module Job
|
||||
module Mail
|
||||
class ConfirmEmail < Base
|
||||
@queue = :mail
|
||||
def self.perform(user_id)
|
||||
Notifier.confirm_email(user_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
11
app/models/jobs/mail/liked.rb
Normal file
11
app/models/jobs/mail/liked.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module Job
|
||||
module Mail
|
||||
class Liked < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, sender_id, like_id)
|
||||
Notifier.liked(recipient_id, sender_id, like_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
15
app/models/jobs/mail/mentioned.rb
Normal file
15
app/models/jobs/mail/mentioned.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
module Job
|
||||
module Mail
|
||||
class Mentioned < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, actor_id, target_id)
|
||||
Notifier.mentioned( recipient_id, actor_id, target_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
15
app/models/jobs/mail/private_message.rb
Normal file
15
app/models/jobs/mail/private_message.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
module Job
|
||||
module Mail
|
||||
class PrivateMessage < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, actor_id, target_id)
|
||||
Notifier.private_message( recipient_id, actor_id, target_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/models/jobs/mail/started_sharing.rb
Normal file
16
app/models/jobs/mail/started_sharing.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
module Job
|
||||
module Mail
|
||||
class StartedSharing < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, sender_id, target_id)
|
||||
Notifier.started_sharing(recipient_id, sender_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
module Job
|
||||
class MailAlsoCommented < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, sender_id, comment_id)
|
||||
Notifier.also_commented(recipient_id, sender_id, comment_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
module Job
|
||||
class MailCommentOnPost < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, sender_id, comment_id)
|
||||
Notifier.comment_on_post(recipient_id, sender_id, comment_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
module Job
|
||||
class MailConfirmEmail < Base
|
||||
@queue = :mail
|
||||
def self.perform(user_id)
|
||||
Notifier.confirm_email(user_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
module Job
|
||||
class MailLiked < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, sender_id, like_id)
|
||||
Notifier.liked(recipient_id, sender_id, like_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
module Job
|
||||
class MailMentioned < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, actor_id, target_id)
|
||||
|
||||
Notifier.mentioned( recipient_id, actor_id, target_id).deliver
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
module Job
|
||||
class MailPrivateMessage < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, actor_id, target_id)
|
||||
Notifier.private_message( recipient_id, actor_id, target_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
module Job
|
||||
class MailStartedSharing < Base
|
||||
@queue = :mail
|
||||
def self.perform(recipient_id, sender_id, target_id)
|
||||
Notifier.started_sharing(recipient_id, sender_id).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
class Notifications::AlsoCommented < Notification
|
||||
def mail_job
|
||||
Job::MailAlsoCommented
|
||||
Job::Mail::AlsoCommented
|
||||
end
|
||||
def popup_translation_key
|
||||
'notifications.also_commented'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class Notifications::CommentOnPost < Notification
|
||||
def mail_job
|
||||
Job::MailCommentOnPost
|
||||
Job::Mail::CommentOnPost
|
||||
end
|
||||
def popup_translation_key
|
||||
'notifications.comment_on_post'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class Notifications::Liked < Notification
|
||||
def mail_job
|
||||
Job::MailLiked
|
||||
Job::Mail::Liked
|
||||
end
|
||||
def popup_translation_key
|
||||
'notifications.liked'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class Notifications::Mentioned < Notification
|
||||
def mail_job
|
||||
Job::MailMentioned
|
||||
Job::Mail::Mentioned
|
||||
end
|
||||
def popup_translation_key
|
||||
'notifications.mentioned'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class Notifications::PrivateMessage < Notification
|
||||
def mail_job
|
||||
Job::MailPrivateMessage
|
||||
Job::Mail::PrivateMessage
|
||||
end
|
||||
def popup_translation_key
|
||||
'notifications.private_message'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class Notifications::RequestAccepted < Notification
|
||||
def mail_job
|
||||
Job::MailRequestAcceptance
|
||||
Job::Mail::RequestAcceptance
|
||||
end
|
||||
def popup_translation_key
|
||||
'notifications.request_accepted'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class Notifications::StartedSharing < Notification
|
||||
def mail_job
|
||||
Job::MailStartedSharing
|
||||
Job::Mail::StartedSharing
|
||||
end
|
||||
|
||||
def popup_translation_key
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
######### Mailer #######################
|
||||
def mail(job, *args)
|
||||
pref = job.to_s.gsub('Job::Mail', '').underscore
|
||||
pref = job.to_s.gsub('Job::Mail::', '').underscore
|
||||
if(self.disable_mail == false && !self.user_preferences.exists?(:email_type => pref))
|
||||
Resque.enqueue(job, *args)
|
||||
end
|
||||
|
|
@ -225,7 +225,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
def mail_confirm_email
|
||||
return false if unconfirmed_email.blank?
|
||||
Resque.enqueue(Job::MailConfirmEmail, id)
|
||||
Resque.enqueue(Job::Mail::ConfirmEmail, id)
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ describe UsersController do
|
|||
end
|
||||
|
||||
it 'sends out activation email on success' do
|
||||
Resque.should_receive(:enqueue).with(Job::MailConfirmEmail, @user.id).once
|
||||
Resque.should_receive(:enqueue).with(Job::Mail::ConfirmEmail, @user.id).once
|
||||
put(:update, :id => @user.id, :user => { :email => "my@newemail.com"})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,18 +4,18 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Job::MailMentioned do
|
||||
describe Job::Mail::Mentioned do
|
||||
describe '#perfom' do
|
||||
it 'should call .deliver on the notifier object' do
|
||||
user = alice
|
||||
sm = Factory(:status_message)
|
||||
m = Mention.new(:person => user.person, :post=> sm)
|
||||
sm = Factory(:status_message)
|
||||
m = Mention.new(:person => user.person, :post=> sm)
|
||||
|
||||
mail_mock = mock()
|
||||
mail_mock.should_receive(:deliver)
|
||||
Notifier.should_receive(:mentioned).with(user.id, sm.author.id, m.id).and_return(mail_mock)
|
||||
|
||||
Job::MailMentioned.perform(user.id, sm.author.id, m.id)
|
||||
Job::Mail::Mentioned.perform(user.id, sm.author.id, m.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Job::MailPrivateMessage do
|
||||
describe Job::Mail::PrivateMessage do
|
||||
describe '#perfom_delegate' do
|
||||
it 'should call .deliver on the notifier object' do
|
||||
user1 = alice
|
||||
|
|
@ -14,14 +14,14 @@ describe Job::MailPrivateMessage do
|
|||
create_hash = { :author => user1.person, :participant_ids => participant_ids ,
|
||||
:subject => "cool stuff", :text => 'hey'}
|
||||
|
||||
cnv = Conversation.create(create_hash)
|
||||
cnv = Conversation.create(create_hash)
|
||||
message = cnv.messages.first
|
||||
|
||||
mail_mock = mock()
|
||||
mail_mock.should_receive(:deliver)
|
||||
Notifier.should_receive(:mentioned).with(user2.id, user1.person.id, message.id).and_return(mail_mock)
|
||||
|
||||
Job::MailMentioned.perform(user2.id, user1.person.id, message.id)
|
||||
Job::Mail::Mentioned.perform(user2.id, user1.person.id, message.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -545,14 +545,14 @@ describe User do
|
|||
alice.disable_mail = false
|
||||
alice.save
|
||||
|
||||
Resque.should_receive(:enqueue).with(Job::MailStartedSharing, alice.id, 'contactrequestid').once
|
||||
alice.mail(Job::MailStartedSharing, alice.id, 'contactrequestid')
|
||||
Resque.should_receive(:enqueue).with(Job::Mail::StartedSharing, alice.id, 'contactrequestid').once
|
||||
alice.mail(Job::Mail::StartedSharing, alice.id, 'contactrequestid')
|
||||
end
|
||||
|
||||
it 'does not enqueue a mail job if the correct corresponding job has a prefrence entry' do
|
||||
alice.user_preferences.create(:email_type => 'started_sharing')
|
||||
Resque.should_not_receive(:enqueue)
|
||||
alice.mail(Job::MailStartedSharing, alice.id, 'contactrequestid')
|
||||
alice.mail(Job::Mail::StartedSharing, alice.id, 'contactrequestid')
|
||||
end
|
||||
|
||||
it 'does not send a mail if disable_mail is set to true' do
|
||||
|
|
@ -560,7 +560,7 @@ describe User do
|
|||
alice.save
|
||||
alice.reload
|
||||
Resque.should_not_receive(:enqueue)
|
||||
alice.mail(Job::MailStartedSharing, alice.id, 'contactrequestid')
|
||||
alice.mail(Job::Mail::StartedSharing, alice.id, 'contactrequestid')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -704,12 +704,12 @@ describe User do
|
|||
describe '#mail_confirm_email' do
|
||||
it 'enqueues a mail job on user with unconfirmed email' do
|
||||
user.update_attribute(:unconfirmed_email, "alice@newmail.com")
|
||||
Resque.should_receive(:enqueue).with(Job::MailConfirmEmail, alice.id).once
|
||||
Resque.should_receive(:enqueue).with(Job::Mail::ConfirmEmail, alice.id).once
|
||||
alice.mail_confirm_email.should eql(true)
|
||||
end
|
||||
|
||||
it 'enqueues NO mail job on user without unconfirmed email' do
|
||||
Resque.should_not_receive(:enqueue).with(Job::MailConfirmEmail, alice.id)
|
||||
Resque.should_not_receive(:enqueue).with(Job::Mail::ConfirmEmail, alice.id)
|
||||
alice.mail_confirm_email.should eql(false)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue