diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/about_me_validator.rb | 12 | ||||
-rw-r--r-- | app/models/change_email_validator.rb | 21 | ||||
-rw-r--r-- | app/models/contact_validator.rb | 15 |
3 files changed, 29 insertions, 19 deletions
diff --git a/app/models/about_me_validator.rb b/app/models/about_me_validator.rb index 8ee505ac8..1bef11aed 100644 --- a/app/models/about_me_validator.rb +++ b/app/models/about_me_validator.rb @@ -12,14 +12,20 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -class AboutMeValidator < ActiveRecord::BaseWithoutTable - strip_attributes! +class AboutMeValidator + include ActiveModel::Validations - column :about_me, :text, "I...", false + attr_accessor :about_me # TODO: Switch to built in validations validate :length_of_about_me + def initialize(attributes = {}) + attributes.each do |name, value| + send("#{name}=", value) + end + end + private def length_of_about_me diff --git a/app/models/change_email_validator.rb b/app/models/change_email_validator.rb index 37eb3c176..515683536 100644 --- a/app/models/change_email_validator.rb +++ b/app/models/change_email_validator.rb @@ -15,22 +15,24 @@ # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -class ChangeEmailValidator < ActiveRecord::BaseWithoutTable - strip_attributes! +class ChangeEmailValidator + include ActiveModel::Validations - column :old_email, :string - column :new_email, :string - column :password, :string - column :user_circumstance, :string - - attr_accessor :logged_in_user + attr_accessor :old_email, :new_email, :password, :user_circumstance, :logged_in_user validates_presence_of :old_email, :message => N_("Please enter your old email address") validates_presence_of :new_email, :message => N_("Please enter your new email address") validates_presence_of :password, :message => N_("Please enter your password"), :unless => :changing_email validate :password_and_format_of_email - def changing_email() + def initialize(attributes = {}) + attributes.each do |name, value| + send("#{name}=", value) + end + end + + + def changing_email self.user_circumstance == 'change_email' end @@ -55,5 +57,4 @@ class ChangeEmailValidator < ActiveRecord::BaseWithoutTable errors.add(:new_email, _("New email doesn't look like a valid address")) end end - end diff --git a/app/models/contact_validator.rb b/app/models/contact_validator.rb index 830ba3019..d01f186a3 100644 --- a/app/models/contact_validator.rb +++ b/app/models/contact_validator.rb @@ -15,13 +15,10 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -class ContactValidator < ActiveRecord::BaseWithoutTable - strip_attributes! +class ContactValidator + include ActiveModel::Validations - column :name, :string - column :email, :string - column :subject, :text - column :message, :text + attr_accessor :name, :email, :subject, :message validates_presence_of :name, :message => N_("Please enter your name") validates_presence_of :email, :message => N_("Please enter your email address") @@ -29,6 +26,12 @@ class ContactValidator < ActiveRecord::BaseWithoutTable validates_presence_of :message, :message => N_("Please enter the message you want to send") validate :email_format + def initialize(attributes = {}) + attributes.each do |name, value| + send("#{name}=", value) + end + end + private def email_format |