Adds max lengths and validations in models
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class Comment < ActiveRecord::Base
|
||||
BODY_LENGTH = {minimum: 10, maximum: 2000}
|
||||
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
acts_as_votable
|
||||
@@ -10,6 +12,8 @@ class Comment < ActiveRecord::Base
|
||||
validates :user, presence: true
|
||||
validates_inclusion_of :commentable_type, in: ["Debate"]
|
||||
|
||||
validates :body, length: BODY_LENGTH
|
||||
|
||||
belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true
|
||||
belongs_to :user, -> { with_hidden }
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
require 'numeric'
|
||||
class Debate < ActiveRecord::Base
|
||||
TITLE_LENGTH = {minimum: 10, maximum: Debate.columns.find { |c| c.name == 'title' }.limit || 80 }
|
||||
DESCRIPTION_LENGTH = {minimum: 10, maximum: 6000}
|
||||
|
||||
apply_simple_captcha
|
||||
TITLE_LENGTH = Debate.columns.find { |c| c.name == 'title' }.limit
|
||||
|
||||
acts_as_votable
|
||||
acts_as_taggable
|
||||
@@ -16,6 +18,9 @@ class Debate < ActiveRecord::Base
|
||||
validates :description, presence: true
|
||||
validates :author, presence: true
|
||||
|
||||
validates :title, length: TITLE_LENGTH
|
||||
validates :description, length: DESCRIPTION_LENGTH
|
||||
|
||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||
|
||||
before_validation :sanitize_description
|
||||
@@ -148,6 +153,6 @@ class Debate < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def sanitize_tag_list
|
||||
self.tag_list = TagSanitizer.new.sanitize_tag_list(self.tag_list)
|
||||
#self.tag_list = TagSanitizer.new.sanitize_tag_list(self.tag_list)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
class Organization < ActiveRecord::Base
|
||||
NAME_LENGTH = {maximum: Organization.columns.find { |c| c.name == 'name' }.limit || 60}
|
||||
|
||||
belongs_to :user, touch: true
|
||||
|
||||
validates :name, presence: true
|
||||
validates :name, length: NAME_LENGTH
|
||||
validates :name, uniqueness: true
|
||||
|
||||
delegate :email, :phone_number, to: :user
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
class User < ActiveRecord::Base
|
||||
include Verification
|
||||
|
||||
OMNIAUTH_EMAIL_PREFIX = 'omniauth@participacion'
|
||||
OMNIAUTH_EMAIL_REGEX = /\A#{OMNIAUTH_EMAIL_PREFIX}/
|
||||
|
||||
USERNAME_LENGTH = {maximum: User.columns.find { |c| c.name == 'username' }.limit || 60}
|
||||
|
||||
include Verification
|
||||
|
||||
apply_simple_captcha
|
||||
devise :database_authenticatable, :registerable, :confirmable,
|
||||
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, :async
|
||||
@@ -23,6 +25,7 @@ class User < ActiveRecord::Base
|
||||
|
||||
validates :username, presence: true, unless: :organization?
|
||||
validates :username, uniqueness: true, unless: :organization?
|
||||
validates :username, length: USERNAME_LENGTH
|
||||
validates :official_level, inclusion: {in: 0..5}
|
||||
validates_format_of :email, without: OMNIAUTH_EMAIL_REGEX, on: :update
|
||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||
|
||||
Reference in New Issue
Block a user