Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormaxwell <maxwell@joindiaspora.com>2011-03-14 21:32:50 +0300
committermaxwell <maxwell@joindiaspora.com>2011-03-14 21:32:59 +0300
commitadbd23ec5031d7fc2bfbf0b4c4924aeb54130d66 (patch)
tree5d128e69500f8f72865100a7a3348dd1e7e895d6
parent28fc093a013391bebe8021207ad83f370938d2a8 (diff)
more tests for mailing. the bug was i think we have to restart the resque workerslast-data-conversion
-rw-r--r--app/models/user.rb9
-rw-r--r--app/models/user_preference.rb18
-rw-r--r--app/views/users/edit.html.haml2
-rw-r--r--spec/models/user_preference_spec.rb7
-rw-r--r--spec/models/user_spec.rb2
5 files changed, 30 insertions, 8 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 684a11ca4..f86024e3a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 9584d13e4..779b0bebb 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -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
diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml
index 8170f6ef9..0d9660666 100644
--- a/app/views/users/edit.html.haml
+++ b/app/views/users/edit.html.haml
@@ -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')
diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rb
index 66613b87d..daee7233d 100644
--- a/spec/models/user_preference_spec.rb
+++ b/spec/models/user_preference_spec.rb
@@ -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
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index fa05afd72..e0afcde49 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -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