updated to listen to disable mail

This commit is contained in:
maxwell 2011-03-11 15:31:43 -08:00
parent 580f0576c8
commit d825eeaaa0
2 changed files with 8 additions and 9 deletions

View file

@ -46,10 +46,13 @@ class User < ActiveRecord::Base
attr_accessible :getting_started, :password, :password_confirmation, :language, :disable_mail attr_accessible :getting_started, :password, :password_confirmation, :language, :disable_mail
def update_user_preferences(pref_hash) def update_user_preferences(pref_hash)
if self.disable_mail
mails = ['mentioned', 'request_received', 'comment_on_post', 'request_acceptence', 'also_commented', 'private_message']
mails.each{|x| self.user_preferences.find_or_create_by_email_type(x)}
self.update_attributes(:disable_mail => false)
end
pref_hash.keys.each do |key| pref_hash.keys.each do |key|
if pref_hash[key] == 'true' if pref_hash[key] == 'true'
self.user_preferences.find_or_create_by_email_type(key) self.user_preferences.find_or_create_by_email_type(key)
@ -175,7 +178,8 @@ class User < ActiveRecord::Base
######### Mailer ####################### ######### Mailer #######################
def mail(job, *args) def mail(job, *args)
unless self.disable_mail pref = job.to_s.gsub('Job::Mail', '').underscore
unless self.disable_mail || self.user_preferences.exists?(:email_type => pref)
Resque.enqueue(job, *args) Resque.enqueue(job, *args)
end end
end end

View file

@ -1,5 +0,0 @@
require 'spec_helper'
describe UserPreferences do
pending "add some examples to (or delete) #{__FILE__}"
end