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)
|
def update_user_preferences(pref_hash)
|
||||||
if self.disable_mail
|
if self.disable_mail
|
||||||
mails = ['mentioned', 'request_received', 'comment_on_post', 'request_acceptance', 'also_commented', 'private_message']
|
UserPreference::VALID_EMAIL_TYPES.each{|x| self.user_preferences.find_or_create_by_email_type(x)}
|
||||||
mails.each{|x| self.user_preferences.find_or_create_by_email_type(x)}
|
|
||||||
self.disable_mail = false
|
self.disable_mail = false
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,17 @@ class UserPreference < ActiveRecord::Base
|
||||||
validate :must_be_valid_email_type
|
validate :must_be_valid_email_type
|
||||||
|
|
||||||
|
|
||||||
def must_be_valid_email_type
|
VALID_EMAIL_TYPES =
|
||||||
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",
|
["mentioned",
|
||||||
"comment_on_post",
|
"comment_on_post",
|
||||||
"private_message",
|
"private_message",
|
||||||
"request_acceptence",
|
"request_acceptance",
|
||||||
"request_received",
|
"request_received",
|
||||||
"also_commented"]
|
"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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ describe UserPreference do
|
||||||
|
|
||||||
it 'should only allow valid email types to exist' do
|
it 'should only allow valid email types to exist' do
|
||||||
pref = alice.user_preferences.new(:email_type => 'not_valid')
|
pref = alice.user_preferences.new(:email_type => 'not_valid')
|
||||||
puts pref.inspect
|
|
||||||
pref.should_not be_valid
|
pref.should_not be_valid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue