From 7e80b8a4dc1b4838df2f9032c7818a5efa4bbcd1 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Wed, 12 Jun 2019 17:10:53 +0000 Subject: [PATCH] Enable the Rails/InverseOf cop and add missing `inverse_of` --- .rubocop.yml | 2 +- app/models/champs/repetition_champ.rb | 2 +- app/models/dossier.rb | 4 ++-- app/models/gestionnaire.rb | 6 +++--- app/models/procedure.rb | 6 +++--- app/models/type_de_champ.rb | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 307bc088d..445c3400a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -726,7 +726,7 @@ Rails/HttpStatus: Enabled: false Rails/InverseOf: - Enabled: false + Enabled: true Rails/LexicallyScopedActionFilter: Enabled: false diff --git a/app/models/champs/repetition_champ.rb b/app/models/champs/repetition_champ.rb index 7f8313e16..50295a6f6 100644 --- a/app/models/champs/repetition_champ.rb +++ b/app/models/champs/repetition_champ.rb @@ -1,5 +1,5 @@ class Champs::RepetitionChamp < Champ - has_many :champs, -> { ordered }, foreign_key: :parent_id, dependent: :destroy + has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy accepts_nested_attributes_for :champs, allow_destroy: true diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 698e265be..3449517ec 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -26,8 +26,8 @@ class Dossier < ApplicationRecord has_many :champs_private, -> { root.private_only.ordered }, class_name: 'Champ', inverse_of: :dossier, dependent: :destroy has_many :commentaires, inverse_of: :dossier, dependent: :destroy has_many :invites, dependent: :destroy - has_many :follows, -> { active } - has_many :previous_follows, -> { inactive }, class_name: 'Follow' + has_many :follows, -> { active }, inverse_of: :dossier + has_many :previous_follows, -> { inactive }, class_name: 'Follow', inverse_of: :dossier has_many :followers_gestionnaires, through: :follows, source: :gestionnaire has_many :previous_followers_gestionnaires, -> { distinct }, through: :previous_follows, source: :gestionnaire has_many :avis, inverse_of: :dossier, dependent: :destroy diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 24a7b5498..c5ab8b7c2 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -12,12 +12,12 @@ class Gestionnaire < ApplicationRecord has_many :assign_to, dependent: :destroy has_many :procedures, through: :assign_to - has_many :assign_to_with_email_notifications, -> { with_email_notifications }, class_name: 'AssignTo' + has_many :assign_to_with_email_notifications, -> { with_email_notifications }, class_name: 'AssignTo', inverse_of: :gestionnaire has_many :procedures_with_email_notifications, through: :assign_to_with_email_notifications, source: :procedure has_many :dossiers, -> { state_not_brouillon }, through: :procedures - has_many :follows, -> { active } - has_many :previous_follows, -> { inactive }, class_name: 'Follow' + has_many :follows, -> { active }, inverse_of: :gestionnaire + has_many :previous_follows, -> { inactive }, class_name: 'Follow', inverse_of: :gestionnaire has_many :followed_dossiers, through: :follows, source: :dossier has_many :previously_followed_dossiers, -> { distinct }, through: :previous_follows, source: :dossier has_many :avis diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 0cfe9a71d..c1eddeba0 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -5,9 +5,9 @@ class Procedure < ApplicationRecord MAX_DUREE_CONSERVATION = 36 - has_many :types_de_piece_justificative, -> { ordered }, dependent: :destroy - has_many :types_de_champ, -> { root.public_only.ordered }, dependent: :destroy - has_many :types_de_champ_private, -> { root.private_only.ordered }, class_name: 'TypeDeChamp', dependent: :destroy + has_many :types_de_piece_justificative, -> { ordered }, inverse_of: :procedure, dependent: :destroy + has_many :types_de_champ, -> { root.public_only.ordered }, inverse_of: :procedure, dependent: :destroy + has_many :types_de_champ_private, -> { root.private_only.ordered }, class_name: 'TypeDeChamp', inverse_of: :procedure, dependent: :destroy has_many :dossiers, dependent: :restrict_with_exception has_many :deleted_dossiers, dependent: :destroy diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index f3b9efe86..924672ec9 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -32,7 +32,7 @@ class TypeDeChamp < ApplicationRecord belongs_to :procedure belongs_to :parent, class_name: 'TypeDeChamp' - has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', dependent: :destroy + has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', inverse_of: :parent, dependent: :destroy store_accessor :options, :cadastres, :quartiers_prioritaires, :parcelles_agricoles, :old_pj delegate :tags_for_template, to: :dynamic_type