Merge pull request #442 from abf/rosa-build:247-validations

set a maximum attributes length
This commit is contained in:
avokhmin 2014-11-29 01:26:03 +04:00
commit 8fb819f708
9 changed files with 34 additions and 10 deletions

View File

@ -13,6 +13,7 @@ class Comment < ActiveRecord::Base
serialize :data
validates :body, :user, :commentable_id, :commentable_type, :project_id, presence: true
validates :body, length: { maximum: 10000 }
scope :for_commit, ->(c) { where(commentable_id: c.id.hex, commentable_type: c.class) }
default_scope { order(:created_at) }

View File

@ -15,7 +15,11 @@ class Group < Avatar
has_many :own_platforms, as: :owner, class_name: 'Platform', dependent: :destroy
validates :owner, presence: true
validates :uname, presence: true, uniqueness: {case_sensitive: false}, format: {with: /\A[a-z0-9_]+\z/}, reserved_name: true
validates :uname, presence: true,
uniqueness: {case_sensitive: false},
format: {with: /\A[a-z0-9_]+\z/},
reserved_name: true,
length: { maximum: 100 }
validate { errors.add(:uname, :taken) if User.by_uname(uname).present? }
scope :opened, -> { all }

View File

@ -36,6 +36,8 @@ class Issue < ActiveRecord::Base
has_one :pull_request#, dependent: :destroy
validates :title, :body, :project, presence: true
validates :title, length: { maximum: 100 }
validates :body, length: { maximum: 10000 }
after_create :set_serial_id
after_create :subscribe_users

View File

@ -42,7 +42,8 @@ class Platform < ActiveRecord::Base
has_many :mass_builds, foreign_key: :save_to_platform_id
validates :description,
presence: true
presence: true,
length: { maximum: 10000 }
validates :visibility,
presence: true,
@ -59,7 +60,8 @@ class Platform < ActiveRecord::Base
validates :name,
uniqueness: { case_sensitive: false },
presence: true,
format: { with: /\A#{NAME_PATTERN}\z/ }
format: { with: /\A#{NAME_PATTERN}\z/ },
length: { maximum: 100 }
validates :distrib_type,
presence: true,

View File

@ -7,7 +7,10 @@ class Product < ActiveRecord::Base
belongs_to :project
has_many :product_build_lists, dependent: :destroy
validates :name, presence: true, uniqueness: { scope: :platform_id }
validates :name, presence: true,
uniqueness: { scope: :platform_id },
length: { maximum: 100 }
validates :project, presence: true
validates :main_script, :params, length: { maximum: 255 }

View File

@ -40,7 +40,8 @@ class Project < ActiveRecord::Base
validates :name, uniqueness: { scope: [:owner_id, :owner_type], case_sensitive: false },
presence: true,
format: { with: /\A#{NAME_REGEXP.source}\z/,
message: I18n.t("activerecord.errors.project.uname") }
message: I18n.t("activerecord.errors.project.uname") },
length: { maximum: 100 }
validates :maintainer, presence: true, unless: :new_record?
validates :url, presence: true, format: { with: /\Ahttps?:\/\/[\S]+\z/ }, if: :mass_import
validates :add_to_repository, presence: true, if: :mass_import

View File

@ -21,9 +21,14 @@ class Repository < ActiveRecord::Base
has_many :build_lists, foreign_key: :save_to_repository_id, dependent: :destroy
validates :description, presence: true
validates :name, uniqueness: { scope: :platform_id, case_sensitive: false }, presence: true,
format: { with: /\A[a-z0-9_\-]+\z/ }
validates :description, presence: true,
length: { maximum: 100 }
validates :name, uniqueness: { scope: :platform_id, case_sensitive: false },
presence: true,
format: { with: /\A[a-z0-9_\-]+\z/ },
length: { maximum: 100 }
validates :publish_builds_only_from_branch, length: { maximum: 255 }
scope :recent, -> { order(:name) }

View File

@ -5,6 +5,7 @@ class Token < ActiveRecord::Base
validates :creator_id, :subject_id, :subject_type, presence: true
validates :authentication_token, presence: true, uniqueness: { case_sensitive: true }
validates :description, length: { maximum: 1000 }
default_scope { order(created_at: :desc) }
scope :by_active, -> { where(status: 'active') }

View File

@ -44,8 +44,13 @@ class User < Avatar
has_many :key_pairs
has_many :ssh_keys, dependent: :destroy
validates :uname, presence: true, uniqueness: { case_sensitive: false },
format: { with: /\A#{NAME_REGEXP.source}\z/ }, reserved_name: true
validates :uname, presence: true,
uniqueness: { case_sensitive: false },
format: { with: /\A#{NAME_REGEXP.source}\z/ },
reserved_name: true,
length: { maximum: 30 }
validates :name, length: { maximum: 100 }
validate { errors.add(:uname, :taken) if Group.by_uname(uname).present? }
validates :role, inclusion: { in: EXTENDED_ROLES }, allow_blank: true
validates :language, inclusion: { in: LANGUAGES }, allow_blank: true