Permalink
Browse files

more tests for mailing. the bug was i think we have to restart the re…

…sque workers
  • Loading branch information...
1 parent 28fc093 commit adbd23ec5031d7fc2bfbf0b4c4924aeb54130d66 @maxwell maxwell committed Mar 14, 2011
View
@@ -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 @@ def build_comment(text, options = {})
######### 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
@@ -1,3 +1,21 @@
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')
@@ -1,5 +1,10 @@
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
View
@@ -228,8 +228,8 @@
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 comments on commit adbd23e

Please sign in to comment.