From 873ac155cabfb1aab8d887d07bc8389617d3f843 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 5 Nov 2018 17:06:48 +0000 Subject: [PATCH 1/1] Improve consistency of text validations --- app/models/diary_entry.rb | 4 ++-- app/models/note_comment.rb | 3 +-- app/models/redaction.rb | 4 ++-- app/models/trace.rb | 5 ++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/models/diary_entry.rb b/app/models/diary_entry.rb index 4990a999a..c49c2d427 100644 --- a/app/models/diary_entry.rb +++ b/app/models/diary_entry.rb @@ -37,8 +37,8 @@ class DiaryEntry < ActiveRecord::Base scope :visible, -> { where(:visible => true) } - validates :title, :body, :presence => true, :invalid_chars => true - validates :title, :length => 1..255 + validates :title, :presence => true, :length => 1..255, :invalid_chars => true + validates :body, :presence => true, :invalid_chars => true validates :latitude, :allow_nil => true, :numericality => { :greater_than_or_equal_to => -90, :less_than_or_equal_to => 90 } diff --git a/app/models/note_comment.rb b/app/models/note_comment.rb index 69a93c532..2347d43d0 100644 --- a/app/models/note_comment.rb +++ b/app/models/note_comment.rb @@ -33,8 +33,7 @@ class NoteComment < ActiveRecord::Base validates :visible, :inclusion => [true, false] validates :author, :associated => true validates :event, :inclusion => %w[opened closed reopened commented hidden] - validates :body, :length => { :maximum => 2000 }, - :invalid_chars => true + validates :body, :length => { :maximum => 2000 }, :invalid_chars => true # Return the comment text def body diff --git a/app/models/redaction.rb b/app/models/redaction.rb index 812224d36..e99460c3b 100644 --- a/app/models/redaction.rb +++ b/app/models/redaction.rb @@ -31,8 +31,8 @@ class Redaction < ActiveRecord::Base has_many :old_ways has_many :old_relations - validates :title, :description, :invalid_chars => true - validates :description, :presence => true + validates :title, :presence => true, :invalid_chars => true + validates :description, :presence => true, :invalid_chars => true validates :description_format, :inclusion => { :in => %w[text html markdown] } # this method overrides the AR default to provide the rich diff --git a/app/models/trace.rb b/app/models/trace.rb index 70b2aebbe..942d160f5 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -38,9 +38,8 @@ class Trace < ActiveRecord::Base scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) } validates :user, :presence => true, :associated => true - validates :name, :presence => true, :length => 1..255 - validates :name, :description, :invalid_chars => true - validates :description, :presence => { :on => :create }, :length => 1..255 + validates :name, :presence => true, :length => 1..255, :invalid_chars => true + validates :description, :presence => { :on => :create }, :length => 1..255, :invalid_chars => true validates :timestamp, :presence => true validates :visibility, :inclusion => %w[private public trackable identifiable] -- 2.39.5