placed all mail jobs in the Job::Mail:: namespace & added into appropriate folders

This commit is contained in:
danielgrippi 2011-08-10 12:12:23 -07:00
parent 1e7a2f327b
commit b6c26611ef
26 changed files with 112 additions and 100 deletions

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,6 +1,6 @@
class Notifications::AlsoCommented < Notification
def mail_job
Job::MailAlsoCommented
Job::Mail::AlsoCommented
end
def popup_translation_key
'notifications.also_commented'

View file

@ -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'

View file

@ -1,6 +1,6 @@
class Notifications::Liked < Notification
def mail_job
Job::MailLiked
Job::Mail::Liked
end
def popup_translation_key
'notifications.liked'

View file

@ -1,6 +1,6 @@
class Notifications::Mentioned < Notification
def mail_job
Job::MailMentioned
Job::Mail::Mentioned
end
def popup_translation_key
'notifications.mentioned'

View file

@ -1,6 +1,6 @@
class Notifications::PrivateMessage < Notification
def mail_job
Job::MailPrivateMessage
Job::Mail::PrivateMessage
end
def popup_translation_key
'notifications.private_message'

View file

@ -1,6 +1,6 @@
class Notifications::RequestAccepted < Notification
def mail_job
Job::MailRequestAcceptance
Job::Mail::RequestAcceptance
end
def popup_translation_key
'notifications.request_accepted'

View file

@ -1,6 +1,6 @@
class Notifications::StartedSharing < Notification
def mail_job
Job::MailStartedSharing
Job::Mail::StartedSharing
end
def popup_translation_key

View file

@ -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

View file

@ -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

View file

@ -4,7 +4,7 @@
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
@ -15,7 +15,7 @@ describe Job::MailMentioned do
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

View file

@ -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
@ -21,7 +21,7 @@ describe Job::MailPrivateMessage do
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

View file

@ -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