From 010024c4f9b24205317011cfff3972e4e5d7f6c8 Mon Sep 17 00:00:00 2001 From: buddhamagnet Date: Sun, 11 Sep 2011 21:39:02 +0100 Subject: [PATCH] continuing refactor of model validation calls to rails 3 syntax --- app/models/person.rb | 8 +++++--- app/models/post.rb | 4 ++-- app/models/profile.rb | 9 +++++---- app/models/request.rb | 6 ++++-- app/models/user.rb | 5 ++--- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index eabe66b9e..e41ad0ab8 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -39,9 +39,11 @@ class Person < ActiveRecord::Base before_destroy :remove_all_traces before_validation :clean_url - - validates_presence_of :url, :profile, :serialized_public_key - validates_uniqueness_of :diaspora_handle + + validates :url, :presence => true + validates :profile, :presence => true + validates :serialized_public_key, :presence => true + validates :diaspora_handle, :uniqueness => true scope :searchable, joins(:profile).where(:profiles => {:searchable => true}) scope :remote, where('people.owner_id IS NULL') diff --git a/app/models/post.rb b/app/models/post.rb index 0aad95f20..91f811241 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -28,8 +28,8 @@ class Post < ActiveRecord::Base has_many :resharers, :class_name => 'Person', :through => :reshares, :source => :author belongs_to :author, :class_name => 'Person' - - validates_uniqueness_of :guid + + validates :guid, :uniqueness => true def diaspora_handle read_attribute(:diaspora_handle) || self.author.diaspora_handle diff --git a/app/models/profile.rb b/app/models/profile.rb index 77341a8a9..162d04cb3 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -12,7 +12,7 @@ class Profile < ActiveRecord::Base acts_as_taggable_on :tags extract_tags_from :tag_string - validates_length_of :tag_list, :maximum => 5 + validates :tag_list, :length => { :maximum => 5 } xml_attr :diaspora_handle xml_attr :first_name @@ -29,9 +29,10 @@ class Profile < ActiveRecord::Base before_save :strip_names after_validation :strip_names - - validates_length_of :first_name, :maximum => 32 - validates_length_of :last_name, :maximum => 32 + + validates :first_name, :length => { :maximum => 32 } + validates :last_name, :length => { :maximum => 32 } + validates_format_of :first_name, :with => /\A[^;]+\z/, :allow_blank => true validates_format_of :last_name, :with => /\A[^;]+\z/, :allow_blank => true validate :max_tags diff --git a/app/models/request.rb b/app/models/request.rb index af97fc7ea..2e412fc86 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -11,8 +11,10 @@ class Request xml_accessor :sender_handle xml_accessor :recipient_handle - - validates_presence_of :sender, :recipient + + validates :sender, :presence => true + validates :recipient, :presence => true + validate :not_already_connected validate :not_friending_yourself diff --git a/app/models/user.rb b/app/models/user.rb index 733de5159..10fef5322 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,9 +18,8 @@ class User < ActiveRecord::Base before_validation :strip_and_downcase_username before_validation :set_current_language, :on => :create - - validates_presence_of :username - validates_uniqueness_of :username + + validates :username, :presence => true, :uniqueness => true validates_format_of :username, :with => /\A[A-Za-z0-9_]+\z/ validates_length_of :username, :maximum => 32 validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES