diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-10-20 10:18:05 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-10-29 13:01:10 +0000 |
commit | 962357cd6d65dbc047cfbf3998e03d13dc130bfd (patch) | |
tree | c39233082a41812afb3c776caa8323f63eec98e3 | |
parent | e5ef51a275927e87fa7b5ee0c6292e17c791b488 (diff) |
Use more meaningful validations in Comment
Use validation method names that describe what the validation does
-rw-r--r-- | app/models/comment.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/app/models/comment.rb b/app/models/comment.rb index 4e5e10898..1dd30a271 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -28,7 +28,8 @@ class Comment < ActiveRecord::Base #validates_presence_of :user # breaks during construction of new ones :( validates_inclusion_of :comment_type, :in => [ 'request' ] - validate :body_of_comment + validate :check_body_has_content, + :check_body_uses_mixed_capitals after_save :event_xapian_update @@ -79,13 +80,18 @@ class Comment < ActiveRecord::Base private - def body_of_comment + def check_body_has_content if body.empty? || body =~ /^\s+$/ errors.add(:body, _("Please enter your annotation")) end + end + def check_body_uses_mixed_capitals unless MySociety::Validate.uses_mixed_capitals(body) - errors.add(:body, _('Please write your annotation using a mixture of capital and lower case letters. This makes it easier for others to read.')) + msg = 'Please write your annotation using a mixture of capital and ' \ + 'lower case letters. This makes it easier for others to read.' + errors.add(:body, _(msg)) end end + end |