From: Andy Allan Date: Wed, 2 Mar 2022 15:00:25 +0000 (+0000) Subject: Merge branch 'pull/3472' X-Git-Tag: live~1787 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/45487e1ff8e7d334792440a2b5b3b1067269bfaf?hp=-c Merge branch 'pull/3472' --- 45487e1ff8e7d334792440a2b5b3b1067269bfaf diff --combined .rubocop_todo.yml index 779b3a8fa,2527192f9..b8e782553 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@@ -1,6 -1,6 +1,6 @@@ # This configuration was generated by # `rubocop --auto-gen-config` - # on 2021-12-28 19:44:27 UTC using RuboCop version 1.24.0. + # on 2022-02-23 19:11:04 UTC using RuboCop version 1.25.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@@ -14,7 -14,7 +14,7 @@@ require - rubocop-rails - rubocop-rake - # Offense count: 544 + # Offense count: 550 # Cop supports --auto-correct. # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https @@@ -63,12 -63,12 +63,12 @@@ Lint/DuplicateBranch - 'app/controllers/geocoder_controller.rb' - 'app/helpers/browse_tags_helper.rb' - # Offense count: 663 + # Offense count: 665 # Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: Max: 189 - # Offense count: 72 + # Offense count: 73 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. # IgnoredMethods: refine Metrics/BlockLength: @@@ -84,12 -84,12 +84,12 @@@ Metrics/BlockNesting Metrics/ClassLength: Max: 313 - # Offense count: 57 + # Offense count: 58 # Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: Max: 25 - # Offense count: 739 + # Offense count: 742 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. Metrics/MethodLength: Max: 179 @@@ -104,7 -104,7 +104,7 @@@ Metrics/ParameterLists Metrics/PerceivedComplexity: Max: 26 - # Offense count: 549 + # Offense count: 550 Minitest/MultipleAssertions: Max: 52 @@@ -155,7 -155,20 +155,20 @@@ Rails/HelperInstanceVariable Exclude: - 'app/helpers/title_helper.rb' - # Offense count: 1 + # Offense count: 16 + # Configuration parameters: IgnoreScopes, Include. + # Include: app/models/**/*.rb + Rails/InverseOf: + Exclude: + - 'app/models/changeset.rb' + - 'app/models/diary_entry.rb' + - 'app/models/friendship.rb' + - 'app/models/issue.rb' + - 'app/models/message.rb' + - 'app/models/note.rb' + - 'app/models/user.rb' + + # Offense count: 2 # Configuration parameters: Include. # Include: app/controllers/**/*.rb Rails/LexicallyScopedActionFilter: @@@ -183,6 -196,18 +196,6 @@@ Rails/OutputSafety - 'lib/rich_text.rb' - 'test/helpers/application_helper_test.rb' -# Offense count: 26 -# Cop supports --auto-correct. -Rails/RedundantPresenceValidationOnBelongsTo: - Enabled: false - -# Offense count: 90 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: strict, flexible -Rails/TimeZone: - Enabled: false - # Offense count: 6 # Cop supports --auto-correct. Rake/Desc: @@@ -192,7 -217,7 +205,7 @@@ - 'lib/tasks/subscribe_diary_authors.rake' - 'lib/tasks/subscribe_old_changesets.rake' - # Offense count: 609 + # Offense count: 617 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never diff --combined app/models/node.rb index c2443974d,f6f0f258e..ad4318487 --- a/app/models/node.rb +++ b/app/models/node.rb @@@ -32,7 -32,7 +32,7 @@@ class Node < ApplicationRecor belongs_to :changeset - has_many :old_nodes, -> { order(:version) } + has_many :old_nodes, -> { order(:version) }, :inverse_of => :current_node has_many :way_nodes has_many :ways, :through => :way_nodes @@@ -49,6 -49,8 +49,6 @@@ :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, @@@ -236,7 -238,7 +236,7 @@@ private def save_with_history! - t = Time.now.getutc + t = Time.now.utc self.version += 1 self.timestamp = t diff --combined app/models/note.rb index aeea0de0d,24ba6854d..8c6137479 --- a/app/models/note.rb +++ b/app/models/note.rb @@@ -22,7 -22,7 +22,7 @@@ class Note < ApplicationRecor include GeoRecord has_many :comments, -> { left_joins(:author).where(:visible => true, :users => { :status => [nil, "active", "confirmed"] }).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id - has_many :all_comments, -> { left_joins(:author).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id + has_many :all_comments, -> { left_joins(:author).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id, :inverse_of => :note validates :id, :uniqueness => true, :presence => { :on => :update }, :numericality => { :on => :update, :only_integer => true } @@@ -45,7 -45,7 +45,7 @@@ # Close a note def close self.status = "closed" - self.closed_at = Time.now.getutc + self.closed_at = Time.now.utc save end diff --combined app/models/old_node.rb index 979f7cb6b,1324c8139..4f5f074ab --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@@ -35,7 -35,7 +35,7 @@@ class OldNode < ApplicationRecor # 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, @@@ -46,10 -46,10 +46,10 @@@ validate :validate_position belongs_to :changeset - belongs_to :redaction + belongs_to :redaction, :optional => true - belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id" + belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id", :inverse_of => :old_nodes - has_many :old_tags, :class_name => "OldNodeTag", :foreign_key => [:node_id, :version] + has_many :old_tags, :class_name => "OldNodeTag", :foreign_key => [:node_id, :version], :inverse_of => :old_node def validate_position errors.add(:base, "Node is not in the world") unless in_world? diff --combined app/models/old_node_tag.rb index ec48c1c04,11a2efd5a..c710e48f1 --- a/app/models/old_node_tag.rb +++ b/app/models/old_node_tag.rb @@@ -16,9 -16,9 +16,9 @@@ class OldNodeTag < ApplicationRecor self.table_name = "node_tags" self.primary_keys = "node_id", "version", "k" - belongs_to :old_node, :foreign_key => [:node_id, :version] + belongs_to :old_node, :foreign_key => [:node_id, :version], :inverse_of => :old_tags - 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 --combined app/models/old_relation.rb index 39d53518d,71bd4b73d..7f9a747e6 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@@ -31,13 -31,13 +31,13 @@@ class OldRelation < ApplicationRecor include Redactable belongs_to :changeset - belongs_to :redaction + belongs_to :redaction, :optional => true - belongs_to :current_relation, :class_name => "Relation", :foreign_key => "relation_id" + belongs_to :current_relation, :class_name => "Relation", :foreign_key => "relation_id", :inverse_of => :old_relations - 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] + has_many :old_members, -> { order(:sequence_id) }, :class_name => "OldRelationMember", :foreign_key => [:relation_id, :version], :inverse_of => :old_relation + has_many :old_tags, :class_name => "OldRelationTag", :foreign_key => [:relation_id, :version], :inverse_of => :old_relation - validates :changeset, :presence => true, :associated => true + validates :changeset, :associated => true validates :timestamp, :presence => true validates :visible, :inclusion => [true, false] diff --combined app/models/old_relation_tag.rb index 124c89ad5,1fccdf7a8..c3a183891 --- a/app/models/old_relation_tag.rb +++ b/app/models/old_relation_tag.rb @@@ -16,9 -16,9 +16,9 @@@ class OldRelationTag < ApplicationRecor self.table_name = "relation_tags" self.primary_keys = "relation_id", "version", "k" - belongs_to :old_relation, :foreign_key => [:relation_id, :version] + belongs_to :old_relation, :foreign_key => [:relation_id, :version], :inverse_of => :old_tags - 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 --combined app/models/old_way.rb index 8052899bf,1f00c46ba..acf88ddcf --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@@ -31,13 -31,13 +31,13 @@@ class OldWay < ApplicationRecor include Redactable belongs_to :changeset - belongs_to :redaction + belongs_to :redaction, :optional => true - belongs_to :current_way, :class_name => "Way", :foreign_key => "way_id" + belongs_to :current_way, :class_name => "Way", :foreign_key => "way_id", :inverse_of => :old_ways - has_many :old_nodes, :class_name => "OldWayNode", :foreign_key => [:way_id, :version] - has_many :old_tags, :class_name => "OldWayTag", :foreign_key => [:way_id, :version] + has_many :old_nodes, :class_name => "OldWayNode", :foreign_key => [:way_id, :version], :inverse_of => :old_way + has_many :old_tags, :class_name => "OldWayTag", :foreign_key => [:way_id, :version], :inverse_of => :old_way - validates :changeset, :presence => true, :associated => true + validates :changeset, :associated => true validates :timestamp, :presence => true validates :visible, :inclusion => [true, false] diff --combined app/models/old_way_tag.rb index bbfffc2cb,e684199bf..0342cf344 --- a/app/models/old_way_tag.rb +++ b/app/models/old_way_tag.rb @@@ -16,9 -16,9 +16,9 @@@ class OldWayTag < ApplicationRecor self.table_name = "way_tags" self.primary_keys = "way_id", "version", "k" - belongs_to :old_way, :foreign_key => [:way_id, :version] + belongs_to :old_way, :foreign_key => [:way_id, :version], :inverse_of => :old_tags - 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 --combined app/models/relation.rb index 021082eda,61ae45c99..0a4a660a6 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@@ -27,9 -27,9 +27,9 @@@ class Relation < ApplicationRecor belongs_to :changeset - has_many :old_relations, -> { order(:version) } + has_many :old_relations, -> { order(:version) }, :inverse_of => :current_relation - has_many :relation_members, -> { order(:sequence_id) } + has_many :relation_members, -> { order(:sequence_id) }, :inverse_of => :relation has_many :relation_tags has_many :containing_relation_members, :class_name => "RelationMember", :as => :member @@@ -39,6 -39,8 +39,6 @@@ :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] @@@ -263,7 -265,7 +263,7 @@@ private def save_with_history! - t = Time.now.getutc + t = Time.now.utc self.version += 1 self.timestamp = t diff --combined app/models/way.rb index 08dc5ed30,0c6e645b7..b11c225dd --- a/app/models/way.rb +++ b/app/models/way.rb @@@ -27,9 -27,9 +27,9 @@@ class Way < ApplicationRecor belongs_to :changeset - has_many :old_ways, -> { order(:version) } + has_many :old_ways, -> { order(:version) }, :inverse_of => :current_way - has_many :way_nodes, -> { order(:sequence_id) } + has_many :way_nodes, -> { order(:sequence_id) }, :inverse_of => :way has_many :nodes, :through => :way_nodes has_many :way_tags @@@ -41,6 -41,8 +41,6 @@@ :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] @@@ -227,7 -229,7 +227,7 @@@ private def save_with_history! - t = Time.now.getutc + t = Time.now.utc self.version += 1 self.timestamp = t