From: Andy Allan Date: Wed, 23 Feb 2022 16:25:43 +0000 (+0000) Subject: Remove redundant presence validation on belongs_to X-Git-Tag: live~1302^2 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/8938ab79975d4152a4d6d3c8ceafdbda30b6b367 Remove redundant presence validation on belongs_to There's no need for us to have it when rails does this for us. --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8c0827ab7..0cdd004a0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -183,11 +183,6 @@ Rails/OutputSafety: - 'lib/rich_text.rb' - 'test/helpers/application_helper_test.rb' -# Offense count: 23 -# Cop supports --auto-correct. -Rails/RedundantPresenceValidationOnBelongsTo: - Enabled: false - # Offense count: 90 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/app/models/changeset.rb b/app/models/changeset.rb index aa674ea7f..9ed22ee94 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -44,8 +44,6 @@ class Changeset < ApplicationRecord validates :id, :uniqueness => true, :presence => { :on => :update }, :numericality => { :on => :update, :only_integer => true } - validates :user_id, :presence => true, - :numericality => { :only_integer => true } validates :num_changes, :presence => true, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 } diff --git a/app/models/changeset_comment.rb b/app/models/changeset_comment.rb index ceb7d3559..1b78f98e8 100644 --- a/app/models/changeset_comment.rb +++ b/app/models/changeset_comment.rb @@ -25,8 +25,8 @@ class ChangesetComment < ApplicationRecord validates :id, :uniqueness => true, :presence => { :on => :update }, :numericality => { :on => :update, :only_integer => true } - validates :changeset, :presence => true, :associated => true - validates :author, :presence => true, :associated => true + validates :changeset, :associated => true + validates :author, :associated => true validates :visible, :inclusion => [true, false] validates :body, :characters => true diff --git a/app/models/changeset_tag.rb b/app/models/changeset_tag.rb index 600ace4a6..672e6f76c 100644 --- a/app/models/changeset_tag.rb +++ b/app/models/changeset_tag.rb @@ -20,7 +20,7 @@ class ChangesetTag < ApplicationRecord belongs_to :changeset - validates :changeset, :presence => true, :associated => true + validates :changeset, :associated => true validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :characters => true validates :k, :uniqueness => { :scope => :changeset_id } end diff --git a/app/models/issue_comment.rb b/app/models/issue_comment.rb index 69aa8bde9..07647d679 100644 --- a/app/models/issue_comment.rb +++ b/app/models/issue_comment.rb @@ -25,6 +25,4 @@ class IssueComment < ApplicationRecord belongs_to :user validates :body, :presence => true, :characters => true - validates :user, :presence => true - validates :issue, :presence => true end diff --git a/app/models/message.rb b/app/models/message.rb index 44b1d8745..49c11e900 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -29,7 +29,7 @@ class Message < ApplicationRecord belongs_to :recipient, :class_name => "User", :foreign_key => :to_user_id validates :title, :presence => true, :utf8 => true, :length => 1..255 - validates :body, :sent_on, :sender, :recipient, :presence => true + validates :body, :sent_on, :presence => true validates :title, :body, :characters => true def self.from_mail(mail, from, to) diff --git a/app/models/node.rb b/app/models/node.rb index 3214564c8..2ae62d684 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -49,8 +49,6 @@ class Node < ApplicationRecord :numericality => { :on => :update, :only_integer => true } validates :version, :presence => true, :numericality => { :only_integer => true } - validates :changeset_id, :presence => true, - :numericality => { :only_integer => true } validates :latitude, :presence => true, :numericality => { :only_integer => true } validates :longitude, :presence => true, diff --git a/app/models/node_tag.rb b/app/models/node_tag.rb index fa21b1ff6..d76a1a0ae 100644 --- a/app/models/node_tag.rb +++ b/app/models/node_tag.rb @@ -17,7 +17,7 @@ class NodeTag < ApplicationRecord belongs_to :node - validates :node, :presence => true, :associated => true + validates :node, :associated => true validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :characters => true validates :k, :uniqueness => { :scope => :node_id } end diff --git a/app/models/note_comment.rb b/app/models/note_comment.rb index 999d04507..635a5b0de 100644 --- a/app/models/note_comment.rb +++ b/app/models/note_comment.rb @@ -29,7 +29,7 @@ class NoteComment < ApplicationRecord validates :id, :uniqueness => true, :presence => { :on => :update }, :numericality => { :on => :update, :only_integer => true } - validates :note, :presence => true, :associated => true + validates :note, :associated => true validates :visible, :inclusion => [true, false] validates :author, :associated => true validates :event, :inclusion => %w[opened closed reopened commented hidden] diff --git a/app/models/old_node.rb b/app/models/old_node.rb index 3261c9a0e..979f7cb6b 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -35,7 +35,7 @@ class OldNode < ApplicationRecord # the queries generated by Redactable will use the wrong table name. include Redactable - validates :changeset, :presence => true, :associated => true + validates :changeset, :associated => true validates :latitude, :presence => true, :numericality => { :only_integer => true } validates :longitude, :presence => true, diff --git a/app/models/old_node_tag.rb b/app/models/old_node_tag.rb index f2cba896c..ec48c1c04 100644 --- a/app/models/old_node_tag.rb +++ b/app/models/old_node_tag.rb @@ -18,7 +18,7 @@ class OldNodeTag < ApplicationRecord belongs_to :old_node, :foreign_key => [:node_id, :version] - validates :old_node, :presence => true, :associated => true + validates :old_node, :associated => true validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :characters => true validates :k, :uniqueness => { :scope => [:node_id, :version] } end diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index e948cae5e..39d53518d 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -37,7 +37,7 @@ class OldRelation < ApplicationRecord has_many :old_members, -> { order(:sequence_id) }, :class_name => "OldRelationMember", :foreign_key => [:relation_id, :version] has_many :old_tags, :class_name => "OldRelationTag", :foreign_key => [:relation_id, :version] - validates :changeset, :presence => true, :associated => true + validates :changeset, :associated => true validates :timestamp, :presence => true validates :visible, :inclusion => [true, false] diff --git a/app/models/old_relation_tag.rb b/app/models/old_relation_tag.rb index d6e6e19c2..124c89ad5 100644 --- a/app/models/old_relation_tag.rb +++ b/app/models/old_relation_tag.rb @@ -18,7 +18,7 @@ class OldRelationTag < ApplicationRecord belongs_to :old_relation, :foreign_key => [:relation_id, :version] - validates :old_relation, :presence => true, :associated => true + validates :old_relation, :associated => true validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :characters => true validates :k, :uniqueness => { :scope => [:relation_id, :version] } end diff --git a/app/models/old_way.rb b/app/models/old_way.rb index 03c281e5a..8052899bf 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -37,7 +37,7 @@ class OldWay < ApplicationRecord has_many :old_nodes, :class_name => "OldWayNode", :foreign_key => [:way_id, :version] has_many :old_tags, :class_name => "OldWayTag", :foreign_key => [:way_id, :version] - validates :changeset, :presence => true, :associated => true + validates :changeset, :associated => true validates :timestamp, :presence => true validates :visible, :inclusion => [true, false] diff --git a/app/models/old_way_tag.rb b/app/models/old_way_tag.rb index 90bf704b6..bbfffc2cb 100644 --- a/app/models/old_way_tag.rb +++ b/app/models/old_way_tag.rb @@ -18,7 +18,7 @@ class OldWayTag < ApplicationRecord belongs_to :old_way, :foreign_key => [:way_id, :version] - validates :old_way, :presence => true, :associated => true + validates :old_way, :associated => true validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :characters => true validates :k, :uniqueness => { :scope => [:way_id, :version] } end diff --git a/app/models/relation.rb b/app/models/relation.rb index 4200a08dd..0adf1012d 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -39,8 +39,6 @@ class Relation < ApplicationRecord :numericality => { :on => :update, :only_integer => true } validates :version, :presence => true, :numericality => { :only_integer => true } - validates :changeset_id, :presence => true, - :numericality => { :only_integer => true } validates :timestamp, :presence => true validates :changeset, :associated => true validates :visible, :inclusion => [true, false] diff --git a/app/models/relation_tag.rb b/app/models/relation_tag.rb index ad9a93266..758ed37cc 100644 --- a/app/models/relation_tag.rb +++ b/app/models/relation_tag.rb @@ -17,7 +17,7 @@ class RelationTag < ApplicationRecord belongs_to :relation - validates :relation, :presence => true, :associated => true + validates :relation, :associated => true validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :characters => true validates :k, :uniqueness => { :scope => :relation_id } end diff --git a/app/models/report.rb b/app/models/report.rb index 346c5eea9..77a967641 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -25,8 +25,6 @@ class Report < ApplicationRecord belongs_to :issue, :counter_cache => true belongs_to :user - validates :issue, :presence => true - validates :user, :presence => true validates :details, :presence => true, :characters => true validates :category, :presence => true diff --git a/app/models/trace.rb b/app/models/trace.rb index feefc0773..f2d81e31a 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -43,7 +43,7 @@ class Trace < ApplicationRecord has_one_attached :image, :service => Settings.trace_image_storage has_one_attached :icon, :service => Settings.trace_icon_storage - validates :user, :presence => true, :associated => true + validates :user, :associated => true validates :name, :presence => true, :length => 1..255, :characters => true validates :description, :presence => { :on => :create }, :length => 1..255, :characters => true validates :timestamp, :presence => true diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index d5cad3978..741aa335a 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -16,6 +16,6 @@ class UserPreference < ApplicationRecord belongs_to :user - validates :user, :presence => true, :associated => true + validates :user, :associated => true validates :k, :v, :length => 1..255, :characters => true end diff --git a/app/models/way.rb b/app/models/way.rb index 933cb7c8b..767289d58 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -41,8 +41,6 @@ class Way < ApplicationRecord :numericality => { :on => :update, :only_integer => true } validates :version, :presence => true, :numericality => { :only_integer => true } - validates :changeset_id, :presence => true, - :numericality => { :only_integer => true } validates :timestamp, :presence => true validates :changeset, :associated => true validates :visible, :inclusion => [true, false] diff --git a/app/models/way_tag.rb b/app/models/way_tag.rb index 0d32d8c41..93c4cdece 100644 --- a/app/models/way_tag.rb +++ b/app/models/way_tag.rb @@ -17,7 +17,7 @@ class WayTag < ApplicationRecord belongs_to :way - validates :way, :presence => true, :associated => true + validates :way, :associated => true validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :characters => true validates :k, :uniqueness => { :scope => :way_id } end