diff --git a/app/models/user.rb b/app/models/user.rb index f86024e3a..cc9ec2609 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 779b0bebb..7d5501ca4 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -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 diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rb index daee7233d..25bbe15d2 100644 --- a/spec/models/user_preference_spec.rb +++ b/spec/models/user_preference_spec.rb @@ -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