change namespace from Mail to Mailers

locally when Resque tried to constantize Jobs::Mail Object.const_get("Jobs") returned our Jobs module but when it tried to const_get("Mail") it returned the Mail gem.
added copyright
This commit is contained in:
Dan Hansen 2011-10-09 22:33:17 -05:00
parent 814eb7b426
commit f859904c76
38 changed files with 144 additions and 53 deletions

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module NotificationMailers
class AlsoCommented < NotificationMailers::Base
include ActionView::Helpers::TextHelper

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module NotificationMailers
TRUNCATION_LEN = 70

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module NotificationMailers
class CommentOnPost < NotificationMailers::Base
include ActionView::Helpers::TextHelper

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module NotificationMailers
class ConfirmEmail < NotificationMailers::Base
def set_headers

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module NotificationMailers
class Liked < NotificationMailers::Base
attr_accessor :like

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module NotificationMailers
class Mentioned < NotificationMailers::Base
attr_accessor :post

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module NotificationMailers
class PrivateMessage < NotificationMailers::Base
attr_accessor :message, :conversation, :participants

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module NotificationMailers
class Reshared < NotificationMailers::Base
attr_accessor :reshare

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module NotificationMailers
class StartedSharing < NotificationMailers::Base
def set_headers

View file

@ -1,3 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Notifier < ActionMailer::Base
helper :application
helper :markdownify

View file

@ -135,7 +135,7 @@ class Invitation < ActiveRecord::Base
def queue_send!
unless self.recipient.present?
Resque.enqueue(Jobs::Mail::InviteUserByEmail, self.id)
Resque.enqueue(Jobs::Mailers::InviteUserByEmail, self.id)
end
end

View file

@ -4,7 +4,7 @@
module Jobs
class Base
Dir["#{Rails.root}/app/models/jobs/mail/*.rb"].each {|file| require file }
Dir["#{Rails.root}/app/models/jobs/mailers/*.rb"].each {|file| require file }
extend ResqueJobLogging
end
end

View file

@ -1,10 +0,0 @@
module Jobs
module Mail
class ConfirmEmail < Base
@queue = :mail
def self.perform(user_id)
Notifier.confirm_email(user_id).deliver
end
end
end
end

View file

@ -1,5 +1,9 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
module Mail
module Mailers
class AlsoCommented < Base
@queue = :mail
def self.perform(recipient_id, sender_id, comment_id)

View file

@ -1,5 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
module Mail
module Mailers
class CommentOnPost < Base
@queue = :mail
def self.perform(recipient_id, sender_id, comment_id)

View file

@ -0,0 +1,14 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
module Mailers
class ConfirmEmail < Base
@queue = :mail
def self.perform(user_id)
Notifier.confirm_email(user_id).deliver
end
end
end
end

View file

@ -2,9 +2,8 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
module Mail
module Mailers
class InviteUserByEmail < Base
@queue = :mail
def self.perform(invite_id)

View file

@ -1,5 +1,9 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
module Mail
module Mailers
class Liked < Base
@queue = :mail
def self.perform(recipient_id, sender_id, like_id)

View file

@ -2,9 +2,8 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
module Mail
module Mailers
class Mentioned < Base
@queue = :mail
def self.perform(recipient_id, actor_id, target_id)

View file

@ -2,11 +2,10 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
module Mail
module Mailers
class PrivateMessage < Base
@queue = :mail
@queue = :mailers
def self.perform(recipient_id, actor_id, target_id)
Notifier.private_message( recipient_id, actor_id, target_id).deliver
end

View file

@ -1,5 +1,9 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
module Mail
module Mailers
class Reshared < Base
@queue = :mail
def self.perform(recipient_id, sender_id, reshare_id)

View file

@ -2,9 +2,8 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
module Mail
module Mailers
class StartedSharing < Base
@queue = :mail
def self.perform(recipient_id, sender_id, target_id)

View file

@ -2,7 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
class ResendInvitation < Base
@queue = :mail

View file

@ -1,6 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Notifications::AlsoCommented < Notification
def mail_job
Jobs::Mail::AlsoCommented
Jobs::Mailers::AlsoCommented
end
def popup_translation_key

View file

@ -1,6 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Notifications::CommentOnPost < Notification
def mail_job
Jobs::Mail::CommentOnPost
Jobs::Mailers::CommentOnPost
end
def popup_translation_key

View file

@ -1,6 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Notifications::Liked < Notification
def mail_job
Jobs::Mail::Liked
Jobs::Mailers::Liked
end
def popup_translation_key

View file

@ -1,6 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Notifications::Mentioned < Notification
def mail_job
Jobs::Mail::Mentioned
Jobs::Mailers::Mentioned
end
def popup_translation_key

View file

@ -1,6 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Notifications::PrivateMessage < Notification
def mail_job
Jobs::Mail::PrivateMessage
Jobs::Mailers::PrivateMessage
end
def popup_translation_key
'notifications.private_message'

View file

@ -1,6 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Notifications::RequestAccepted < Notification
def mail_job
Jobs::Mail::RequestAcceptance
Jobs::Mailers::RequestAcceptance
end
def popup_translation_key
'notifications.request_accepted'

View file

@ -1,7 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Notifications::Reshared < Notification
def mail_job
Jobs::Mail::Reshared
#Jobs::Mail::Liked
Jobs::Mailers::Reshared
end
def popup_translation_key

View file

@ -1,6 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Notifications::StartedSharing < Notification
def mail_job
Jobs::Mail::StartedSharing
Jobs::Mailers::StartedSharing
end
def popup_translation_key

View file

@ -267,15 +267,15 @@ class User < ActiveRecord::Base
######### Mailer #######################
def mail(job, *args)
pref = job.to_s.gsub('Jobs::Mail::', '').underscore
pref = job.to_s.gsub('Jobs::Mailers::', '').underscore
if(self.disable_mail == false && !self.user_preferences.exists?(:email_type => pref))
Resque.enqueue(job, *args)
end
end
def mail_confirm_email
def mail_confirm_email
return false if unconfirmed_email.blank?
Resque.enqueue(Jobs::Mail::ConfirmEmail, id)
Resque.enqueue(Jobs::Mailers::ConfirmEmail, id)
true
end

View file

@ -136,7 +136,7 @@ describe UsersController do
end
it 'sends out activation email on success' do
Resque.should_receive(:enqueue).with(Jobs::Mail::ConfirmEmail, @user.id).once
Resque.should_receive(:enqueue).with(Jobs::Mailers::ConfirmEmail, @user.id).once
put(:update, :id => @user.id, :user => { :email => "my@newemail.com"})
end
end

View file

@ -1,6 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe Jobs::Mail::InviteUserByEmail do
describe Jobs::Mailers::InviteUserByEmail do
before do
@sender = alice
@email = 'bob@bob.com'
@ -12,6 +16,6 @@ describe Jobs::Mail::InviteUserByEmail do
invitation = Invitation.create(:sender => @sender, :identifier => @email, :service => "email", :aspect => @aspect, :message => @message)
invitation.should_receive(:send!)
Invitation.stub(:find).and_return(invitation)
Jobs::Mail::InviteUserByEmail.perform(invitation.id)
Jobs::Mailers::InviteUserByEmail.perform(invitation.id)
end
end

View file

@ -4,7 +4,7 @@
require 'spec_helper'
describe Jobs::Mail::Mentioned do
describe Jobs::Mailers::Mentioned do
describe '#perfom' do
it 'should call .deliver on the notifier object' do
user = alice
@ -15,7 +15,7 @@ describe Jobs::Mail::Mentioned do
mail_mock.should_receive(:deliver)
Notifier.should_receive(:mentioned).with(user.id, sm.author.id, m.id).and_return(mail_mock)
Jobs::Mail::Mentioned.perform(user.id, sm.author.id, m.id)
Jobs::Mailers::Mentioned.perform(user.id, sm.author.id, m.id)
end
end
end

View file

@ -4,7 +4,7 @@
require 'spec_helper'
describe Jobs::Mail::PrivateMessage do
describe Jobs::Mailers::PrivateMessage do
describe '#perfom_delegate' do
it 'should call .deliver on the notifier object' do
user1 = alice
@ -21,7 +21,7 @@ describe Jobs::Mail::PrivateMessage do
mail_mock.should_receive(:deliver)
Notifier.should_receive(:mentioned).with(user2.id, user1.person.id, message.id).and_return(mail_mock)
Jobs::Mail::Mentioned.perform(user2.id, user1.person.id, message.id)
Jobs::Mailers::Mentioned.perform(user2.id, user1.person.id, message.id)
end
end
end

View file

@ -4,7 +4,7 @@
require 'spec_helper'
describe Jobs::Mail::Reshared do
describe Jobs::Mailers::Reshared do
describe '#perfom' do
it 'should call .deliver on the notifier object' do
sm = Factory(:status_message, :author => bob.person, :public => true)
@ -14,7 +14,7 @@ describe Jobs::Mail::Reshared do
mail_mock.should_receive(:deliver)
Notifier.should_receive(:reshared).with(bob.id, reshare.author.id, reshare.id).and_return(mail_mock)
Jobs::Mail::Reshared.perform(bob.id, reshare.author.id, reshare.id)
Jobs::Mailers::Reshared.perform(bob.id, reshare.author.id, reshare.id)
end
end
end

View file

@ -661,14 +661,14 @@ describe User do
alice.disable_mail = false
alice.save
Resque.should_receive(:enqueue).with(Jobs::Mail::StartedSharing, alice.id, 'contactrequestid').once
alice.mail(Jobs::Mail::StartedSharing, alice.id, 'contactrequestid')
Resque.should_receive(:enqueue).with(Jobs::Mailers::StartedSharing, alice.id, 'contactrequestid').once
alice.mail(Jobs::Mailers::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(Jobs::Mail::StartedSharing, alice.id, 'contactrequestid')
alice.mail(Jobs::Mailers::StartedSharing, alice.id, 'contactrequestid')
end
it 'does not send a mail if disable_mail is set to true' do
@ -676,7 +676,7 @@ describe User do
alice.save
alice.reload
Resque.should_not_receive(:enqueue)
alice.mail(Jobs::Mail::StartedSharing, alice.id, 'contactrequestid')
alice.mail(Jobs::Mailers::StartedSharing, alice.id, 'contactrequestid')
end
end
@ -823,12 +823,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(Jobs::Mail::ConfirmEmail, alice.id).once
Resque.should_receive(:enqueue).with(Jobs::Mailers::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(Jobs::Mail::ConfirmEmail, alice.id)
Resque.should_not_receive(:enqueue).with(Jobs::Mailers::ConfirmEmail, alice.id)
alice.mail_confirm_email.should eql(false)
end
end