Skip to content
Extraits de code Groupes Projets
Valider 5791ffba rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Add administrative mail method

parent b2f4e064
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -4,6 +4,23 @@ class Notifier < ActionMailer::Base
ATTACHMENT = File.read("#{Rails.root}/public/images/diaspora_white_on_grey.png")
def self.admin(string, recipients, opts = {})
mails = []
recipients.each do |rec|
mail = single_admin(string, rec)
mails << mail
mail.deliver
end
mails
end
def single_admin(string, recipient)
@recipient = recipient
@string = string.html_safe
attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT
mail(:to => @recipient.email,
:subject => I18n.t('notifier.single_admin.subject'), :host => APP_CONFIG[:terse_pod_url])
end
def new_request(recipient_id, sender_id)
@receiver = User.find_by_id(recipient_id)
@sender = Person.find_by_id(sender_id)
......
%p
= t('notifier.hello', :name => @recipient.username)
%p
= @string
%br
= t('notifier.thanks')
= t('notifier.single_admin.admin')
= t('notifier.hello', :name => @recipient.username)
= @string
= t('notifier.thanks')
= t('notifier.single_admin.admin')
......@@ -367,7 +367,11 @@ en:
notifier:
hello: "Hello %{name}!"
love: "love,"
thanks: "Thanks,"
diaspora: "the diaspora email robot"
single_admin:
subject: "A message from your Diaspora administrator:"
admin: "Your Diaspora administrator"
new_request:
subject: "new Diaspora* contact request from %{from}"
just_sent_you: "just sent you a contact request on Diaspora*"
......
......@@ -6,11 +6,46 @@ describe Notifier do
let!(:user) {make_user}
let!(:aspect) {user.aspects.create(:name => "science")}
let!(:person) {Factory.create :person}
let!(:request_mail) {Notifier.new_request(user.id, person.id)}
let!(:request_accepted_mail) {Notifier.request_accepted(user.id, person.id, aspect.id)}
before do
Notifier.deliveries = []
end
describe '.administrative' do
it 'mails a user' do
mails = Notifier.admin("Welcome to bureaucracy!", [user])
mails.length.should == 1
mail = Notifier.deliveries.first
mail.to.should == [user.email]
mail.body.encoded.should match /Welcome to bureaucracy!/
mail.body.encoded.should match /#{user.username}/
end
it 'mails a bunch of users' do
users = []
5.times do
users << make_user
end
Notifier.admin("Welcome to bureaucracy!", users)
mails = Notifier.deliveries
mails.length.should == 5
mails.each{|mail|
this_user = users.detect{|u| mail.to == [u.email]}
mail.body.encoded.should match /Welcome to bureaucracy!/
mail.body.encoded.should match /#{this_user.username}/
}
end
end
describe '#single_admin' do
it 'mails a user' do
mail = Notifier.single_admin("Welcome to bureaucracy!", user)
mail.to.should == [user.email]
mail.body.encoded.should match /Welcome to bureaucracy!/
mail.body.encoded.should match /#{user.username}/
end
end
describe "#new_request" do
let!(:request_mail) {Notifier.new_request(user.id, person.id)}
it 'goes to the right person' do
request_mail.to.should == [user.email]
end
......@@ -30,6 +65,7 @@ describe Notifier do
end
describe "#request_accpeted" do
let!(:request_accepted_mail) {Notifier.request_accepted(user.id, person.id, aspect.id)}
it 'goes to the right person' do
request_accepted_mail.to.should == [user.email]
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter