fix typo, puts in a test, and made the emails types a constant in UserPreferences
This commit is contained in:
parent
2cd6e89e5c
commit
b14ac9606f
3 changed files with 8 additions and 11 deletions
|
|
@ -48,8 +48,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
def update_user_preferences(pref_hash)
|
||||
if self.disable_mail
|
||||
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)}
|
||||
UserPreference::VALID_EMAIL_TYPES.each{|x| self.user_preferences.find_or_create_by_email_type(x)}
|
||||
self.disable_mail = false
|
||||
self.save
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,18 +4,17 @@ class UserPreference < ActiveRecord::Base
|
|||
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
|
||||
VALID_EMAIL_TYPES =
|
||||
["mentioned",
|
||||
"comment_on_post",
|
||||
"private_message",
|
||||
"request_acceptence",
|
||||
"request_acceptance",
|
||||
"request_received",
|
||||
"also_commented"]
|
||||
|
||||
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
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ describe UserPreference do
|
|||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue