more tests for mailing. the bug was i think we have to restart the resque workers
This commit is contained in:
parent
28fc093a01
commit
adbd23ec50
5 changed files with 30 additions and 8 deletions
|
|
@ -48,9 +48,10 @@ 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|
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue