From b6c26611ef1a1adc468fb93cb4300cdd61ffa14d Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 10 Aug 2011 12:12:23 -0700 Subject: [PATCH] placed all mail jobs in the Job::Mail:: namespace & added into appropriate folders --- app/models/jobs/mail/also_commented.rb | 11 +++++++++++ app/models/jobs/mail/comment_on_post.rb | 11 +++++++++++ app/models/jobs/mail/confirm_email.rb | 10 ++++++++++ app/models/jobs/mail/liked.rb | 11 +++++++++++ app/models/jobs/mail/mentioned.rb | 15 +++++++++++++++ app/models/jobs/mail/private_message.rb | 15 +++++++++++++++ app/models/jobs/mail/started_sharing.rb | 16 ++++++++++++++++ app/models/jobs/mail_also_commented.rb | 9 --------- app/models/jobs/mail_comment_on_post.rb | 9 --------- app/models/jobs/mail_confirm_email.rb | 8 -------- app/models/jobs/mail_liked.rb | 9 --------- app/models/jobs/mail_mentioned.rb | 15 --------------- app/models/jobs/mail_private_message.rb | 13 ------------- app/models/jobs/mail_started_sharing.rb | 14 -------------- app/models/notifications/also_commented.rb | 2 +- app/models/notifications/comment_on_post.rb | 2 +- app/models/notifications/liked.rb | 2 +- app/models/notifications/mentioned.rb | 2 +- app/models/notifications/private_message.rb | 2 +- app/models/notifications/request_accepted.rb | 2 +- app/models/notifications/started_sharing.rb | 2 +- app/models/user.rb | 4 ++-- spec/controllers/users_controller_spec.rb | 2 +- .../jobs/{ => mail}/mail_mentioned_spec.rb | 8 ++++---- .../jobs/{ => mail}/mail_private_message.rb | 6 +++--- spec/models/user_spec.rb | 12 ++++++------ 26 files changed, 112 insertions(+), 100 deletions(-) create mode 100644 app/models/jobs/mail/also_commented.rb create mode 100644 app/models/jobs/mail/comment_on_post.rb create mode 100644 app/models/jobs/mail/confirm_email.rb create mode 100644 app/models/jobs/mail/liked.rb create mode 100644 app/models/jobs/mail/mentioned.rb create mode 100644 app/models/jobs/mail/private_message.rb create mode 100644 app/models/jobs/mail/started_sharing.rb delete mode 100644 app/models/jobs/mail_also_commented.rb delete mode 100644 app/models/jobs/mail_comment_on_post.rb delete mode 100644 app/models/jobs/mail_confirm_email.rb delete mode 100644 app/models/jobs/mail_liked.rb delete mode 100644 app/models/jobs/mail_mentioned.rb delete mode 100644 app/models/jobs/mail_private_message.rb delete mode 100644 app/models/jobs/mail_started_sharing.rb rename spec/models/jobs/{ => mail}/mail_mentioned_spec.rb (70%) rename spec/models/jobs/{ => mail}/mail_private_message.rb (82%) diff --git a/app/models/jobs/mail/also_commented.rb b/app/models/jobs/mail/also_commented.rb new file mode 100644 index 000000000..58c1fea76 --- /dev/null +++ b/app/models/jobs/mail/also_commented.rb @@ -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 + diff --git a/app/models/jobs/mail/comment_on_post.rb b/app/models/jobs/mail/comment_on_post.rb new file mode 100644 index 000000000..4ab734474 --- /dev/null +++ b/app/models/jobs/mail/comment_on_post.rb @@ -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 + diff --git a/app/models/jobs/mail/confirm_email.rb b/app/models/jobs/mail/confirm_email.rb new file mode 100644 index 000000000..f09b33a3d --- /dev/null +++ b/app/models/jobs/mail/confirm_email.rb @@ -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 diff --git a/app/models/jobs/mail/liked.rb b/app/models/jobs/mail/liked.rb new file mode 100644 index 000000000..07ede82c1 --- /dev/null +++ b/app/models/jobs/mail/liked.rb @@ -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 + diff --git a/app/models/jobs/mail/mentioned.rb b/app/models/jobs/mail/mentioned.rb new file mode 100644 index 000000000..3ea5e0451 --- /dev/null +++ b/app/models/jobs/mail/mentioned.rb @@ -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 diff --git a/app/models/jobs/mail/private_message.rb b/app/models/jobs/mail/private_message.rb new file mode 100644 index 000000000..fcf0b0dfc --- /dev/null +++ b/app/models/jobs/mail/private_message.rb @@ -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 diff --git a/app/models/jobs/mail/started_sharing.rb b/app/models/jobs/mail/started_sharing.rb new file mode 100644 index 000000000..8656fe829 --- /dev/null +++ b/app/models/jobs/mail/started_sharing.rb @@ -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 + diff --git a/app/models/jobs/mail_also_commented.rb b/app/models/jobs/mail_also_commented.rb deleted file mode 100644 index 0d1b472bc..000000000 --- a/app/models/jobs/mail_also_commented.rb +++ /dev/null @@ -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 - diff --git a/app/models/jobs/mail_comment_on_post.rb b/app/models/jobs/mail_comment_on_post.rb deleted file mode 100644 index 6aee1d08b..000000000 --- a/app/models/jobs/mail_comment_on_post.rb +++ /dev/null @@ -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 - diff --git a/app/models/jobs/mail_confirm_email.rb b/app/models/jobs/mail_confirm_email.rb deleted file mode 100644 index 6f564c02b..000000000 --- a/app/models/jobs/mail_confirm_email.rb +++ /dev/null @@ -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 diff --git a/app/models/jobs/mail_liked.rb b/app/models/jobs/mail_liked.rb deleted file mode 100644 index a93636e65..000000000 --- a/app/models/jobs/mail_liked.rb +++ /dev/null @@ -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 - diff --git a/app/models/jobs/mail_mentioned.rb b/app/models/jobs/mail_mentioned.rb deleted file mode 100644 index 4fdc9b478..000000000 --- a/app/models/jobs/mail_mentioned.rb +++ /dev/null @@ -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 diff --git a/app/models/jobs/mail_private_message.rb b/app/models/jobs/mail_private_message.rb deleted file mode 100644 index 35530ce49..000000000 --- a/app/models/jobs/mail_private_message.rb +++ /dev/null @@ -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 diff --git a/app/models/jobs/mail_started_sharing.rb b/app/models/jobs/mail_started_sharing.rb deleted file mode 100644 index ee914fda6..000000000 --- a/app/models/jobs/mail_started_sharing.rb +++ /dev/null @@ -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 - diff --git a/app/models/notifications/also_commented.rb b/app/models/notifications/also_commented.rb index 61b1346d3..b731ef2ca 100644 --- a/app/models/notifications/also_commented.rb +++ b/app/models/notifications/also_commented.rb @@ -1,6 +1,6 @@ class Notifications::AlsoCommented < Notification def mail_job - Job::MailAlsoCommented + Job::Mail::AlsoCommented end def popup_translation_key 'notifications.also_commented' diff --git a/app/models/notifications/comment_on_post.rb b/app/models/notifications/comment_on_post.rb index 7235daadb..44fca16d6 100644 --- a/app/models/notifications/comment_on_post.rb +++ b/app/models/notifications/comment_on_post.rb @@ -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' diff --git a/app/models/notifications/liked.rb b/app/models/notifications/liked.rb index 8b32b9eb5..96ddd3a16 100644 --- a/app/models/notifications/liked.rb +++ b/app/models/notifications/liked.rb @@ -1,6 +1,6 @@ class Notifications::Liked < Notification def mail_job - Job::MailLiked + Job::Mail::Liked end def popup_translation_key 'notifications.liked' diff --git a/app/models/notifications/mentioned.rb b/app/models/notifications/mentioned.rb index e7a2d3e75..3bf93fd53 100644 --- a/app/models/notifications/mentioned.rb +++ b/app/models/notifications/mentioned.rb @@ -1,6 +1,6 @@ class Notifications::Mentioned < Notification def mail_job - Job::MailMentioned + Job::Mail::Mentioned end def popup_translation_key 'notifications.mentioned' diff --git a/app/models/notifications/private_message.rb b/app/models/notifications/private_message.rb index 394442cba..036643297 100644 --- a/app/models/notifications/private_message.rb +++ b/app/models/notifications/private_message.rb @@ -1,6 +1,6 @@ class Notifications::PrivateMessage < Notification def mail_job - Job::MailPrivateMessage + Job::Mail::PrivateMessage end def popup_translation_key 'notifications.private_message' diff --git a/app/models/notifications/request_accepted.rb b/app/models/notifications/request_accepted.rb index 4486a5021..bdb351dd1 100644 --- a/app/models/notifications/request_accepted.rb +++ b/app/models/notifications/request_accepted.rb @@ -1,6 +1,6 @@ class Notifications::RequestAccepted < Notification def mail_job - Job::MailRequestAcceptance + Job::Mail::RequestAcceptance end def popup_translation_key 'notifications.request_accepted' diff --git a/app/models/notifications/started_sharing.rb b/app/models/notifications/started_sharing.rb index a39f30b71..fcd8877a8 100644 --- a/app/models/notifications/started_sharing.rb +++ b/app/models/notifications/started_sharing.rb @@ -1,6 +1,6 @@ class Notifications::StartedSharing < Notification def mail_job - Job::MailStartedSharing + Job::Mail::StartedSharing end def popup_translation_key diff --git a/app/models/user.rb b/app/models/user.rb index eaff8af9a..d99102ec6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 71f187156..6d83383b5 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -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 diff --git a/spec/models/jobs/mail_mentioned_spec.rb b/spec/models/jobs/mail/mail_mentioned_spec.rb similarity index 70% rename from spec/models/jobs/mail_mentioned_spec.rb rename to spec/models/jobs/mail/mail_mentioned_spec.rb index ec9056249..6afa2736e 100644 --- a/spec/models/jobs/mail_mentioned_spec.rb +++ b/spec/models/jobs/mail/mail_mentioned_spec.rb @@ -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 diff --git a/spec/models/jobs/mail_private_message.rb b/spec/models/jobs/mail/mail_private_message.rb similarity index 82% rename from spec/models/jobs/mail_private_message.rb rename to spec/models/jobs/mail/mail_private_message.rb index 81598405d..8d1820fd1 100644 --- a/spec/models/jobs/mail_private_message.rb +++ b/spec/models/jobs/mail/mail_private_message.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 391eb9ee7..821ea7a5b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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