From b14ac9606f45a06814e460f805e13d4f2f930494 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 14 Mar 2011 12:21:23 -0700 Subject: [PATCH] fix typo, puts in a test, and made the emails types a constant in UserPreferences --- app/models/user.rb | 3 +-- app/models/user_preference.rb | 15 +++++++-------- spec/models/user_preference_spec.rb | 1 - 3 files changed, 8 insertions(+), 11 deletions(-) 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