修改了部分model的validate(custon_field.rb之上)

This commit is contained in:
sw 2014-10-15 11:08:41 +08:00
parent 602982a124
commit 4082dbed5b
18 changed files with 68 additions and 73 deletions

View File

@ -2,6 +2,7 @@ class Activity < ActiveRecord::Base
attr_accessible :act_id, :act_type, :user_id
belongs_to :act, :polymorphic => true
belongs_to :user
validates_presence_of :act_id, :act_type, :user_id
validates :act_id, presence: true
validates :act_type, presence: true
validates :user_id, presence: true
end

View File

@ -28,10 +28,10 @@ class Attachment < ActiveRecord::Base
include UserScoreHelper
validates_presence_of :filename, :author
validates_length_of :filename, :maximum => 254
validates_length_of :disk_filename, :maximum => 254
validates_length_of :description, :maximum => 254
validates :filename, presence: true, length: {maximum: 254}
validates :author, presence: true
validates :disk_filename, length: {maximum: 254}
validates :description, length: {maximum: 254}
validate :validate_max_file_size

View File

@ -26,9 +26,7 @@ class AuthSource < ActiveRecord::Base
has_many :users
validates_presence_of :name
validates_uniqueness_of :name
validates_length_of :name, :maximum => 60
validates :name, presence: true, uniqueness: true, length: {maximum: 60}
def authenticate(login, password)
end

View File

@ -20,14 +20,20 @@ require 'net/ldap/dn'
require 'timeout'
class AuthSourceLdap < AuthSource
validates_presence_of :host, :port, :attr_login
validates_length_of :name, :host, :maximum => 60, :allow_nil => true
validates_length_of :account, :account_password, :base_dn, :filter, :maximum => 255, :allow_blank => true
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true
validates_numericality_of :port, :only_integer => true
validates_numericality_of :timeout, :only_integer => true, :allow_blank => true
validates :host, presence: true, length: {maximum: 60, allow_nil: true}
validates :port, presence: true, numericality: {only_integer: true}
validates :attr_login, presence: true
validates :name, length: {maximum: 60, allow_nil: true}
validates :account, length: {maximum: 255, allow_blank: true}
validates :account_password, length: {maximum: 255, allow_blank: true}
validates :base_dn, length: {maximum: 255, allow_blank: true}
validates :filter, length: {maximum: 255, allow_blank: true}
validates :attr_login, length: {maximum: 30, allow_nil: true}
validates :attr_firstname, length: {maximum: 30, allow_nil: true}
validates :attr_lastname, length: {maximum: 30, allow_nil: true}
validates :attr_mail, length: {maximum: 30, allow_nil: true}
validates :timeout, numericality: { only_integer: true, allow_blank: true}
validate :validate_filter
before_validation :strip_ldap_attributes
def initialize(attributes=nil, *args)

View File

@ -37,16 +37,14 @@ class Bid < ActiveRecord::Base
NAME_LENGTH_LIMIT = 60
DESCRIPTION_LENGTH_LIMIT = 250
validates_length_of :name, :maximum => NAME_LENGTH_LIMIT
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
validates_presence_of :author_id, :name, :deadline
# validates_presence_of :deadline, :message => 'test'
# validates_format_of :deadline, :with =>
validates_format_of :deadline, :with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/
validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/,
:if => Proc.new { |p| p.reward_type == 1 }
validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{1})$/, :if => Proc.new { |p| p.reward_type == 3 }
validates :name, length: {maximum: NAME_LENGTH_LIMIT}, presence: true
validates :description, length: {maximum: DESCRIPTION_LENGTH_LIMIT}
validates :author_id, presence: true
validates :deadline, presence: true, format: {:with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/}
validates :name, length: {maximum: NAME_LENGTH_LIMIT}
validates :budget,
format: {with : /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/, if: Proc.new { |p| p.reward_type == 1 }},
format: {with: /^(\d+)$|^(\d+).([0-9]{1})$/, if: Proc.new { |p| p.reward_type == 3 }}
validate :validate_user
validate :validate_reward_type
after_create :act_as_activity

View File

@ -7,13 +7,13 @@ class BidingProject < ActiveRecord::Base
belongs_to :user
DESCRIPTION_LENGTH_LIMIT = 500
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
validates_presence_of :user_id, :bid_id, :project_id
validates :description, length: {maximum: DESCRIPTION_LENGTH_LIMIT}
validates :user_id, presence: true
validates :bid_id, presence: true, :uniqueness => { :scope => :project_id}
validates :project_id, presence: true
validate :validate_user
validate :validate_bid
validate :validate_project
validates_uniqueness_of :bid_id, :scope => :project_id
def self.cerate_bidding(bid_id, project_id, description = nil)
self.create(:user_id => User.current.id, :bid_id => bid_id,

View File

@ -26,9 +26,8 @@ class Board < ActiveRecord::Base
acts_as_list :scope => '(project_id = #{project_id} AND parent_id #{parent_id ? "= #{parent_id}" : "IS NULL"})'
acts_as_watchable
validates_presence_of :name, :description
validates_length_of :name, :maximum => 30
validates_length_of :description, :maximum => 255
validates :name, presence: true, length: {maximum: 30}
validates :description, presence: true, length: {maximum: 255}
validate :validate_board
scope :visible, lambda {|*args|

View File

@ -2,11 +2,10 @@ class BugToOsp < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :open_source_project, :foreign_key => "osp_id"
belongs_to :bug, :class_name => 'RelativeMemo', :foreign_key => "relative_memo_id"
validates_presence_of :osp_id, :relative_memo_id
validates :osp_id, presence: true
validates :relative_memo_id, presence: true
scope :visible, lambda {|*args|
nil
}
end

View File

@ -18,7 +18,9 @@
class Change < ActiveRecord::Base
belongs_to :changeset
validates_presence_of :changeset_id, :action, :path
validates :changeset_id, presence: true
validates :action, presence: true
validates :path, presence: true
before_save :init_path
before_validation :replace_invalid_utf8_of_path

View File

@ -54,10 +54,11 @@ class Changeset < ActiveRecord::Base
acts_as_activity_provider :timestamp => "#{table_name}.committed_on",
:author_key => :user_id,
:find_options => {:include => [:user, {:repository => :project}]}
validates_presence_of :repository_id, :revision, :committed_on, :commit_date
validates_uniqueness_of :revision, :scope => :repository_id
validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
validates :repository_id, presence: true
validates :revision, presence: true, uniqueness: {scope: :repository_id}
validates :committed_on, presence: true
validates :commit_date, presence: true
validates :scmid, uniqueness: {scope: :repository_id, allow_nil: true}
scope :visible, lambda {|*args|
includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))

View File

@ -19,8 +19,6 @@ class Comment < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :commented, :polymorphic => true, :counter_cache => true
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
validates_presence_of :commented, :author, :comments
safe_attributes 'comments'
end

View File

@ -21,13 +21,11 @@ class Contest < ActiveRecord::Base
NAME_LENGTH_LIMIT = 60
DESCRIPTION_LENGTH_LIMIT = 250
validates_length_of :name, :maximum => NAME_LENGTH_LIMIT
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
validates_presence_of :author_id, :name, :budget
#validates_format_of :deadline, :with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/
validates_format_of :deadline, :with =>/^[1-9][0-9]{3}\-0?[1-9]|1[12]\-0?[1-9]|[12]\d|3[01]$/
# validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/
validates :name, length: {maximum: NAME_LENGTH_LIMIT}, presence: true
validates :description, length: {maximum: DESCRIPTION_LENGTH_LIMIT}
validates :author_id, presence: true
validates :budget, presence: true
validates :deadline, format: {:with =>/^[1-9][0-9]{3}\-0?[1-9]|1[12]\-0?[1-9]|[12]\d|3[01]$/}
validate :validate_user
after_create :act_as_activity

View File

@ -1,4 +1,4 @@
class ContestNotification < ActiveRecord::Base
attr_accessible :content, :title
validates_length_of :title, maximum: 30
validates :title, length: {maximum: 30}
end

View File

@ -6,13 +6,13 @@ class ContestingProject < ActiveRecord::Base
belongs_to :user
DESCRIPTION_LENGTH_LIMIT = 500
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
validates_presence_of :user_id, :contest_id, :project_id
validates :description, length: {maximum:DESCRIPTION_LENGTH_LIMIT }
validates :user_id, presence: true
validates :contest_id, presence: true, uniqueness: {:scope => :project_id}
validates :project_id, presence: true
validate :validate_user
validate :validate_contest
validate :validate_project
validates_uniqueness_of :contest_id, :scope => :project_id
def self.create_contesting(contest_id, project_id, description = nil)
self.create(:user_id => User.current.id, :contest_id => contest_id,

View File

@ -8,10 +8,9 @@ class Contestnotification < ActiveRecord::Base
has_many :notificationcomments, as: :notificationcommented, :dependent => :delete_all, :order => "created_at"
# fq
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
validates_presence_of :title, :description
validates_length_of :title, :maximum => 60
validates_length_of :summary, :maximum => 255
validates :title, length: {maximum: 60}, presence: true
validates :description, presence: true
validates :summary, length: {maximum: 255}
acts_as_attachable :delete_permission => :manage_contestnotifications
acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :contest
@ -19,12 +18,9 @@ class Contestnotification < ActiveRecord::Base
acts_as_activity_provider :find_options => {:include => [:contest, :author]},
:author_key => :author_id
acts_as_watchable
after_create :add_author_as_watcher
after_create :act_as_activity
scope :visible, lambda {|*args|
nil
#includes(:contest).where(Contest.allowed_to_condition(args.shift || User.current, :view_contestnotifications, *args))

View File

@ -10,7 +10,6 @@ class Course < ActiveRecord::Base
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher该方法通过tea_id来调用User表
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school该方法通过school_id来调用School表
has_many :bid
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many :memberships, :class_name => 'Member'
has_many :member_principals, :class_name => 'Member',
@ -34,10 +33,10 @@ class Course < ActiveRecord::Base
acts_as_attachable :view_permission => :view_files,
:delete_permission => :manage_files
validates_presence_of :password, :term,:name ,:class_period
validates_format_of :class_period, :with =>/^\d*$/
#validates_format_of :name,:with =>/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/
validates :password, presence: true
validates :term, presence: true
validates :name, presence: true
validates :class_period, presence: true,format: {:with =>/^\d*$/}
before_save :self_validate
after_create :create_board_sync
before_destroy :delete_all_members

View File

@ -1,7 +1,5 @@
class CourseStatus < ActiveRecord::Base
attr_accessible :changesets_count, :course_ac_para, :course_id, :grade, :watchers_count
belongs_to :course
validates_presence_of :course_id
validates_uniqueness_of :course_id
validates :course_id, presence: true,uniqueness: true
end

View File

@ -1,6 +1,8 @@
class WebFooterCompany < ActiveRecord::Base
attr_accessible :logo_size, :name, :url
validates_presence_of :name,:url
validates_length_of :name,:url, :maximum => 255
validates_format_of :url,:with => /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?/,:message => l(:is_not_url_error)
validates :name, presence: true, length: { maximum: 500 }
validates :url, length: { maximum: 500 },
format: { with: /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?/,
message: l(:is_not_url_error)
}
end