Skip to content
Extraits de code Groupes Projets
Valider adbd23ec rédigé par maxwell's avatar maxwell
Parcourir les fichiers

more tests for mailing. the bug was i think we have to restart the resque workers

parent 28fc093a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -48,11 +48,12 @@ class User < ActiveRecord::Base
def update_user_preferences(pref_hash)
if self.disable_mail
mails = ['mentioned', 'request_received', 'comment_on_post', 'request_acceptence', 'also_commented', 'private_message']
mails = ['mentioned', 'request_received', 'comment_on_post', 'request_acceptance', 'also_commented', 'private_message']
mails.each{|x| self.user_preferences.find_or_create_by_email_type(x)}
self.update_attributes(:disable_mail => false)
self.disable_mail = false
self.save
end
pref_hash.keys.each do |key|
if pref_hash[key] == 'true'
self.user_preferences.find_or_create_by_email_type(key)
......@@ -179,9 +180,7 @@ class User < ActiveRecord::Base
######### Mailer #######################
def mail(job, *args)
pref = job.to_s.gsub('Job::Mail', '').underscore
puts pref
unless self.disable_mail || self.user_preferences.exists?(:email_type => pref)
puts 'im mailin'
Resque.enqueue(job, *args)
end
end
......
class UserPreference < ActiveRecord::Base
belongs_to :user
validate :must_be_valid_email_type
def must_be_valid_email_type
unless valid_email_types.include?(self.email_type)
errors.add(:email_type, 'supplied mail type is not a valid or known email type')
end
end
def valid_email_types
["mentioned",
"comment_on_post",
"private_message",
"request_acceptence",
"request_received",
"also_commented"]
end
end
......@@ -106,7 +106,7 @@
%br
%p.checkbox_select
= type.label t('.request_acceptence')
= type.check_box :request_acceptence, {:checked => @email_prefs['request_acceptance']}, false, true
= type.check_box :request_acceptance, {:checked => @email_prefs['request_acceptance']}, false, true
%br
= f.submit t('.change')
......
require 'spec_helper'
describe UserPreference do
pending "add some examples to (or delete) #{__FILE__}"
it 'should only allow valid email types to exist' do
pref = alice.user_preferences.new(:email_type => 'not_valid')
puts pref.inspect
pref.should_not be_valid
end
end
......@@ -228,8 +228,8 @@ describe User do
proc {
alice.update_user_preferences({'mentioned' => false})
}.should change(alice.user_preferences, :count).by(5)
alice.reload.disable_mail.should be_false
end
end
describe ".find_for_authentication" do
......
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