diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a2046a7ab52..ac04f833d38 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2025-06-18 14:45:47 UTC using RuboCop version 1.76.0. +# on 2025-06-23 09:07:03 UTC using RuboCop version 1.76.0. # 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 @@ Gemspec/OrderedDependencies: Exclude: - 'core/solidus_core.gemspec' -# Offense count: 182 +# Offense count: 186 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: with_first_argument, with_fixed_indentation @@ -332,7 +332,7 @@ Rails/FilePath: - 'core/lib/spree/testing_support/dummy_app.rb' - 'sample/lib/spree/sample.rb' -# Offense count: 53 +# Offense count: 49 # Configuration parameters: Include. # Include: **/app/models/**/*.rb Rails/HasManyOrHasOneDependent: @@ -374,11 +374,24 @@ Rails/IndexWith: - 'core/lib/spree/core/search/variant.rb' - 'core/lib/spree/preferences/preferable.rb' -# Offense count: 26 +# Offense count: 21 # Configuration parameters: IgnoreScopes, Include. # Include: **/app/models/**/*.rb Rails/InverseOf: - Enabled: false + Exclude: + - 'core/app/models/concerns/spree/user_methods.rb' + - 'core/app/models/spree/country.rb' + - 'core/app/models/spree/credit_card.rb' + - 'core/app/models/spree/inventory_unit.rb' + - 'core/app/models/spree/order.rb' + - 'core/app/models/spree/price.rb' + - 'core/app/models/spree/refund.rb' + - 'core/app/models/spree/return_authorization.rb' + - 'core/app/models/spree/return_item.rb' + - 'core/app/models/spree/shipping_method.rb' + - 'core/app/models/spree/store_credit.rb' + - 'core/app/models/spree/store_credit_type.rb' + - 'core/app/models/spree/variant.rb' # Offense count: 24 # Configuration parameters: Include. diff --git a/legacy_promotions/app/models/spree/promotion/actions/create_adjustment.rb b/legacy_promotions/app/models/spree/promotion/actions/create_adjustment.rb index 1fe3430914a..ab173d3e30e 100644 --- a/legacy_promotions/app/models/spree/promotion/actions/create_adjustment.rb +++ b/legacy_promotions/app/models/spree/promotion/actions/create_adjustment.rb @@ -7,7 +7,7 @@ class CreateAdjustment < PromotionAction include Spree::CalculatedAdjustments include Spree::AdjustmentSource - has_many :adjustments, as: :source + has_many :adjustments, as: :source, dependent: :restrict_with_error delegate :eligible?, to: :promotion diff --git a/legacy_promotions/app/models/spree/promotion/actions/create_item_adjustments.rb b/legacy_promotions/app/models/spree/promotion/actions/create_item_adjustments.rb index b2195fc884f..9a3d6068f6a 100644 --- a/legacy_promotions/app/models/spree/promotion/actions/create_item_adjustments.rb +++ b/legacy_promotions/app/models/spree/promotion/actions/create_item_adjustments.rb @@ -7,7 +7,7 @@ class CreateItemAdjustments < PromotionAction include Spree::CalculatedAdjustments include Spree::AdjustmentSource - has_many :adjustments, as: :source + has_many :adjustments, as: :source, dependent: :restrict_with_error delegate :eligible?, to: :promotion diff --git a/legacy_promotions/app/models/spree/promotion/actions/create_quantity_adjustments.rb b/legacy_promotions/app/models/spree/promotion/actions/create_quantity_adjustments.rb index 063dbd33478..8be423755ee 100644 --- a/legacy_promotions/app/models/spree/promotion/actions/create_quantity_adjustments.rb +++ b/legacy_promotions/app/models/spree/promotion/actions/create_quantity_adjustments.rb @@ -6,7 +6,7 @@ module Actions class CreateQuantityAdjustments < CreateItemAdjustments preference :group_size, :integer, default: 1 - has_many :line_item_actions, foreign_key: :action_id, dependent: :destroy + has_many :line_item_actions, foreign_key: :action_id, dependent: :destroy, inverse_of: :action has_many :line_items, through: :line_item_actions ## diff --git a/legacy_promotions/app/models/spree/promotion/rules/product.rb b/legacy_promotions/app/models/spree/promotion/rules/product.rb index 2ebc1da0892..eb3eba42843 100644 --- a/legacy_promotions/app/models/spree/promotion/rules/product.rb +++ b/legacy_promotions/app/models/spree/promotion/rules/product.rb @@ -8,8 +8,11 @@ module Rules # either come from assigned product group or are assingned directly to # the rule. class Product < PromotionRule - has_many :product_promotion_rules, dependent: :destroy, foreign_key: :promotion_rule_id, - class_name: 'Spree::ProductPromotionRule' + has_many :product_promotion_rules, + dependent: :destroy, + foreign_key: :promotion_rule_id, + class_name: 'Spree::ProductPromotionRule', + inverse_of: :promotion_rule has_many :products, class_name: 'Spree::Product', through: :product_promotion_rules def preload_relations diff --git a/legacy_promotions/app/models/spree/promotion/rules/store.rb b/legacy_promotions/app/models/spree/promotion/rules/store.rb index 21e4c91b507..10000a24538 100644 --- a/legacy_promotions/app/models/spree/promotion/rules/store.rb +++ b/legacy_promotions/app/models/spree/promotion/rules/store.rb @@ -4,9 +4,11 @@ module Spree class Promotion module Rules class Store < PromotionRule - has_many :promotion_rule_stores, class_name: "Spree::PromotionRuleStore", - foreign_key: :promotion_rule_id, - dependent: :destroy + has_many :promotion_rule_stores, + class_name: "Spree::PromotionRuleStore", + foreign_key: :promotion_rule_id, + dependent: :destroy, + inverse_of: :promotion_rule has_many :stores, through: :promotion_rule_stores, class_name: "Spree::Store" def preload_relations diff --git a/legacy_promotions/app/models/spree/promotion/rules/taxon.rb b/legacy_promotions/app/models/spree/promotion/rules/taxon.rb index c1375258417..f7fd29a155e 100644 --- a/legacy_promotions/app/models/spree/promotion/rules/taxon.rb +++ b/legacy_promotions/app/models/spree/promotion/rules/taxon.rb @@ -4,8 +4,11 @@ module Spree class Promotion < Spree::Base module Rules class Taxon < PromotionRule - has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon', foreign_key: :promotion_rule_id, - dependent: :destroy + has_many :promotion_rule_taxons, + class_name: 'Spree::PromotionRuleTaxon', + foreign_key: :promotion_rule_id, + dependent: :destroy, + inverse_of: :promotion_rule has_many :taxons, through: :promotion_rule_taxons, class_name: 'Spree::Taxon' def preload_relations diff --git a/legacy_promotions/app/models/spree/promotion/rules/user.rb b/legacy_promotions/app/models/spree/promotion/rules/user.rb index 2f7b23d1817..898ac63910d 100644 --- a/legacy_promotions/app/models/spree/promotion/rules/user.rb +++ b/legacy_promotions/app/models/spree/promotion/rules/user.rb @@ -4,9 +4,11 @@ module Spree class Promotion < Spree::Base module Rules class User < PromotionRule - has_many :promotion_rule_users, class_name: 'Spree::PromotionRuleUser', - foreign_key: :promotion_rule_id, - dependent: :destroy + has_many :promotion_rule_users, + class_name: 'Spree::PromotionRuleUser', + foreign_key: :promotion_rule_id, + dependent: :destroy, + inverse_of: :promotion_rule has_many :users, through: :promotion_rule_users, class_name: Spree::UserClassHandle.new def preload_relations diff --git a/legacy_promotions/app/models/spree/promotion_category.rb b/legacy_promotions/app/models/spree/promotion_category.rb index 603a8e64d06..ddeb614ba30 100644 --- a/legacy_promotions/app/models/spree/promotion_category.rb +++ b/legacy_promotions/app/models/spree/promotion_category.rb @@ -3,6 +3,6 @@ module Spree class PromotionCategory < Spree::Base validates :name, presence: true - has_many :promotions + has_many :promotions, dependent: :nullify end end diff --git a/legacy_promotions/app/models/spree/promotion_code.rb b/legacy_promotions/app/models/spree/promotion_code.rb index c3c72e414bc..0fc944d0e7f 100644 --- a/legacy_promotions/app/models/spree/promotion_code.rb +++ b/legacy_promotions/app/models/spree/promotion_code.rb @@ -3,7 +3,7 @@ class Spree::PromotionCode < Spree::Base belongs_to :promotion, inverse_of: :codes, optional: true belongs_to :promotion_code_batch, class_name: "Spree::PromotionCodeBatch", optional: true - has_many :adjustments + has_many :adjustments, dependent: :restrict_with_error before_validation :normalize_code