Skip to content

Commit

Permalink
Updating validations to Radiant 1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
JediFreeman committed Jan 23, 2014
1 parent 9c41acc commit f976cf7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 31 deletions.
6 changes: 3 additions & 3 deletions app/models/layout_validation_extender.rb
Expand Up @@ -4,9 +4,9 @@ module LayoutValidationExtender
def self.included(base)
base.class_eval do
base.clear_validations
validates_presence_of :name, :message => 'required', :name => :layout_name_presence
validates_uniqueness_of :name, :message => 'name already in use', :name => :layout_name_uniqueness
validates_length_of :name, :maximum => 100, :message => '{{count}}-character limit', :name => :layout_name_length
validates_presence_of :name, :name => :layout_name_presence
validates_uniqueness_of :name, :name => :layout_name_uniqueness
validates_length_of :name, :maximum => 100, :name => :layout_name_length
end
end
end
10 changes: 10 additions & 0 deletions app/models/page_field_validation_extender.rb
@@ -0,0 +1,10 @@
require 'active_record_validation_extender'

module PageFieldValidationExtender
def self.included(base)
base.class_eval do
base.clear_validations
validates_presence_of :name, :name => :page_field_name_presence
end
end
end
10 changes: 5 additions & 5 deletions app/models/page_part_validation_extender.rb
Expand Up @@ -3,11 +3,11 @@
module PagePartValidationExtender
def self.included(base)
base.class_eval do
base.clear_validations
validates_presence_of :name, :message => 'required', :name => :page_part_name_presence
validates_length_of :name, :maximum => 100, :message => '{{count}}-character limit', :name => :page_part_name_length
validates_length_of :filter_id, :maximum => 25, :allow_nil => true, :message => '{{count}}-character limit', :name => :page_part_filter_id_length
validates_numericality_of :id, :page_id, :allow_nil => true, :only_integer => true, :message => 'must be a number', :name => :page_part_id_numericality
base.clear_validations

validates_presence_of :name, :name => :page_part_name_presence
validates_length_of :name, :maximum => 100, :name => :page_part_name_length
validates_length_of :filter_id, :maximum => 25, :allow_nil => true, :name => :page_part_filter_id_length
end
end
end
15 changes: 8 additions & 7 deletions app/models/page_validation_extender.rb
Expand Up @@ -4,14 +4,15 @@ module PageValidationExtender
def self.included(base)
base.class_eval do
base.clear_validations
validates_presence_of :title, :slug, :breadcrumb, :status_id, :message => 'required', :name => :page_title_presence

validates_length_of :title, :maximum => 255, :message => '{{count}}-character limit', :name => :page_title_length
validates_length_of :slug, :maximum => 100, :message => '{{count}}-character limit', :name => :page_slug_length
validates_length_of :breadcrumb, :maximum => 160, :message => '{{count}}-character limit', :name => :page_breadcrumb_length
validates_format_of :slug, :with => %r{^([-_.A-Za-z0-9]*|/)$}, :message => 'invalid format', :name => :page_slug_format
validates_uniqueness_of :slug, :scope => :parent_id, :message => 'slug already in use for child of parent', :name => :page_slug_uniqueness
validates_numericality_of :id, :status_id, :parent_id, :allow_nil => true, :only_integer => true, :message => 'must be a number', :name => :page_numericality
validates_presence_of :title, :slug, :breadcrumb, :status_id, :name => :page_title_presence

validates_length_of :title, :maximum => 255, :name => :page_title_length
validates_length_of :slug, :maximum => 100, :name => :page_slug_length
validates_length_of :breadcrumb, :maximum => 160, :name => :page_breadcrumb_length

validates_format_of :slug, :with => %r{^([-_.A-Za-z0-9]*|/)$}, :name => :page_slug_format
validates_uniqueness_of :slug, :scope => :parent_id, :name => :page_slug_uniqueness

# no need to set name for this, just override the valid_class_name function to replace this behavior
validate :valid_class_name
Expand Down
21 changes: 10 additions & 11 deletions app/models/user_validation_extender.rb
Expand Up @@ -4,21 +4,20 @@ module UserValidationExtender
def self.included(base)
base.class_eval do
base.clear_validations
validates_uniqueness_of :login, :message => 'login already in use', :name => :user_login_uniqueness

validates_confirmation_of :password, :message => 'must match confirmation', :if => :confirm_password?, :name => :user_password_confirmation
validates_uniqueness_of :login, :name => :user_login_uniqueness

validates_presence_of :name, :login, :message => 'required', :name => :user_name_login_presence
validates_presence_of :password, :password_confirmation, :message => 'required', :if => :new_record?, :name => :user_password_presence
validates_confirmation_of :password, :if => :confirm_password?, :name => :user_password_confirmation

validates_format_of :email, :message => 'invalid e-mail address', :allow_nil => true, :with => /^$|^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :name => :user_email_format
validates_presence_of :name, :login, :name => :user_name_login_presence
validates_presence_of :password, :password_confirmation, :if => :new_record?, :name => :user_password_presence

validates_length_of :name, :maximum => 100, :allow_nil => true, :message => '{{count}}-character limit', :name => :user_name_length
validates_length_of :login, :within => 3..40, :allow_nil => true, :too_long => '{{count}}-character limit', :too_short => '{{count}}-character minimum', :name => :user_login_length
validates_length_of :password, :within => 5..40, :allow_nil => true, :too_long => '{{count}}-character limit', :too_short => '{{count}}-character minimum', :if => :validate_length_of_password?, :name => :user_password_length
validates_length_of :email, :maximum => 255, :allow_nil => true, :message => '{{count}}-character limit', :name => :user_email_length

validates_numericality_of :id, :only_integer => true, :allow_nil => true, :message => 'must be a number', :name => :user_id_numericality
validates_format_of :email, :allow_nil => true, :with => /^$|^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :name => :user_email_format

validates_length_of :name, :maximum => 100, :allow_nil => true, :name => :user_name_length
validates_length_of :login, :within => 3..40, :allow_nil => true, :name => :user_login_length
validates_length_of :password, :within => 5..40, :allow_nil => true, :if => :validate_length_of_password?, :name => :user_password_length
validates_length_of :email, :maximum => 255, :allow_nil => true, :name => :user_email_length
end
end
end
11 changes: 6 additions & 5 deletions radiant_validators_extension.rb
Expand Up @@ -14,10 +14,11 @@ class RadiantValidatorsExtension < Radiant::Extension
end

def activate
Page.send :include, PageValidationExtender
Layout.send :include, LayoutValidationExtender
PagePart.send :include, PagePartValidationExtender
Snippet.send :include, SnippetValidationExtender
User.send :include, UserValidationExtender
Page.send :include, PageValidationExtender
PageField.send :include, PageFieldValidationExtender
Layout.send :include, LayoutValidationExtender
PagePart.send :include, PagePartValidationExtender
Snippet.send :include, SnippetValidationExtender
User.send :include, UserValidationExtender
end
end

0 comments on commit f976cf7

Please sign in to comment.