From cfa659c47efcc8327afb55211cfd57c08a78b801 Mon Sep 17 00:00:00 2001 From: buddhamagnet Date: Sun, 11 Sep 2011 21:31:39 +0100 Subject: [PATCH] refactored model validations to use newer rails 3 syntax --- app/models/aspect.rb | 4 ++-- app/models/aspect_visibility.rb | 4 ++-- app/models/comment.rb | 6 +++--- app/models/contact.rb | 2 +- app/models/invitation.rb | 3 ++- app/models/like.rb | 3 ++- app/models/mention.rb | 4 ++-- app/models/message.rb | 4 ++-- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/models/aspect.rb b/app/models/aspect.rb index feeec4af1..4979a96f0 100644 --- a/app/models/aspect.rb +++ b/app/models/aspect.rb @@ -10,9 +10,9 @@ class Aspect < ActiveRecord::Base has_many :aspect_visibilities has_many :posts, :through => :aspect_visibilities + + validates :name, :presence => true, :length => { :maximum => 20 } - validates_presence_of :name - validates_length_of :name, :maximum => 20 validates_uniqueness_of :name, :scope => :user_id, :case_sensitive => false attr_accessible :name, :contacts_visible, :order_id diff --git a/app/models/aspect_visibility.rb b/app/models/aspect_visibility.rb index a0fd0ec3b..cfb6d0d92 100644 --- a/app/models/aspect_visibility.rb +++ b/app/models/aspect_visibility.rb @@ -5,9 +5,9 @@ class AspectVisibility < ActiveRecord::Base belongs_to :aspect - validates_presence_of :aspect + validates :aspect, :presence => true belongs_to :post - validates_presence_of :post + validates :post, :presence => true end diff --git a/app/models/comment.rb b/app/models/comment.rb index 694a6d935..7beaef490 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -25,9 +25,9 @@ class Comment < ActiveRecord::Base belongs_to :post belongs_to :author, :class_name => 'Person' - - validates_presence_of :text, :post - validates_length_of :text, :maximum => 2500 + + validates :text, :presence => true, :length => { :maximum => 2500 } + validates :post, :presence => true serialize :youtube_titles, Hash diff --git a/app/models/contact.rb b/app/models/contact.rb index 64512044d..00b6dde9f 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -7,7 +7,7 @@ class Contact < ActiveRecord::Base validates_presence_of :user belongs_to :person - validates_presence_of :person + validates :person, :presence => true has_many :aspect_memberships has_many :aspects, :through => :aspect_memberships diff --git a/app/models/invitation.rb b/app/models/invitation.rb index 4875c521e..77cf2139d 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -13,7 +13,8 @@ class Invitation < ActiveRecord::Base before_validation :set_email_as_default_service # before_create :share_with_exsisting_user, :if => :recipient_id? - validates_presence_of :identifier, :service + validates :identifier, :presence => true + validates :service, :presence => true validate :valid_identifier? validate :recipient_not_on_pod? validates_presence_of :sender, :aspect, :unless => :admin? diff --git a/app/models/like.rb b/app/models/like.rb index 16e3475f6..d3f144988 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -20,7 +20,8 @@ class Like < ActiveRecord::Base belongs_to :author, :class_name => 'Person' validates_uniqueness_of :target_id, :scope => [:target_type, :author_id] - validates_presence_of :author, :target + validates :author, :presence => true + validates :target, :presence => true after_create do self.target.update_likes_counter diff --git a/app/models/mention.rb b/app/models/mention.rb index bc253fe89..2c2acd85b 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -5,8 +5,8 @@ class Mention < ActiveRecord::Base belongs_to :post belongs_to :person - validates_presence_of :post - validates_presence_of :person + validates :post, :presence => true + validates :person, :presence => true after_destroy :delete_notification diff --git a/app/models/message.rb b/app/models/message.rb index a2a05b933..16cde59a2 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -13,8 +13,8 @@ class Message < ActiveRecord::Base belongs_to :author, :class_name => 'Person' belongs_to :conversation, :touch => true - - validates_presence_of :text + + validates :text, :presence => true after_create do #sign comment as commenter