Skip to content

Commit a9d8d37

Browse files
committed
Legacy Promotions: Add inverse_of/dependent options
1 parent e6a57c3 commit a9d8d37

File tree

10 files changed

+29
-19
lines changed

10 files changed

+29
-19
lines changed

.rubocop_todo.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-06-06 06:59:49 UTC using RuboCop version 1.76.0.
3+
# on 2025-06-06 10:38:29 UTC using RuboCop version 1.76.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -14,7 +14,7 @@ Gemspec/OrderedDependencies:
1414
Exclude:
1515
- 'core/solidus_core.gemspec'
1616

17-
# Offense count: 175
17+
# Offense count: 179
1818
# This cop supports safe autocorrection (--autocorrect).
1919
# Configuration parameters: EnforcedStyle, IndentationWidth.
2020
# SupportedStyles: with_first_argument, with_fixed_indentation
@@ -337,7 +337,7 @@ Rails/FilePath:
337337
- 'core/lib/spree/testing_support/dummy_app.rb'
338338
- 'sample/lib/spree/sample.rb'
339339

340-
# Offense count: 61
340+
# Offense count: 57
341341
# Configuration parameters: Include.
342342
# Include: **/app/models/**/*.rb
343343
Rails/HasManyOrHasOneDependent:
@@ -379,7 +379,7 @@ Rails/IndexWith:
379379
- 'core/lib/spree/core/search/variant.rb'
380380
- 'core/lib/spree/preferences/preferable.rb'
381381

382-
# Offense count: 35
382+
# Offense count: 30
383383
# Configuration parameters: IgnoreScopes, Include.
384384
# Include: **/app/models/**/*.rb
385385
Rails/InverseOf:

legacy_promotions/app/models/spree/promotion/actions/create_adjustment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class CreateAdjustment < PromotionAction
77
include Spree::CalculatedAdjustments
88
include Spree::AdjustmentSource
99

10-
has_many :adjustments, as: :source
10+
has_many :adjustments, as: :source, dependent: :restrict_with_error
1111

1212
delegate :eligible?, to: :promotion
1313

legacy_promotions/app/models/spree/promotion/actions/create_item_adjustments.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class CreateItemAdjustments < PromotionAction
77
include Spree::CalculatedAdjustments
88
include Spree::AdjustmentSource
99

10-
has_many :adjustments, as: :source
10+
has_many :adjustments, as: :source, dependent: :restrict_with_error
1111

1212
delegate :eligible?, to: :promotion
1313

legacy_promotions/app/models/spree/promotion/actions/create_quantity_adjustments.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Actions
66
class CreateQuantityAdjustments < CreateItemAdjustments
77
preference :group_size, :integer, default: 1
88

9-
has_many :line_item_actions, foreign_key: :action_id, dependent: :destroy
9+
has_many :line_item_actions, foreign_key: :action_id, dependent: :destroy, inverse_of: :action
1010
has_many :line_items, through: :line_item_actions
1111

1212
##

legacy_promotions/app/models/spree/promotion/rules/product.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ module Rules
88
# either come from assigned product group or are assingned directly to
99
# the rule.
1010
class Product < PromotionRule
11-
has_many :product_promotion_rules, dependent: :destroy, foreign_key: :promotion_rule_id,
12-
class_name: 'Spree::ProductPromotionRule'
11+
has_many :product_promotion_rules,
12+
dependent: :destroy,
13+
foreign_key: :promotion_rule_id,
14+
class_name: 'Spree::ProductPromotionRule',
15+
inverse_of: :promotion_rule
1316
has_many :products, class_name: 'Spree::Product', through: :product_promotion_rules
1417

1518
def preload_relations

legacy_promotions/app/models/spree/promotion/rules/store.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ module Spree
44
class Promotion
55
module Rules
66
class Store < PromotionRule
7-
has_many :promotion_rule_stores, class_name: "Spree::PromotionRuleStore",
8-
foreign_key: :promotion_rule_id,
9-
dependent: :destroy
7+
has_many :promotion_rule_stores,
8+
class_name: "Spree::PromotionRuleStore",
9+
foreign_key: :promotion_rule_id,
10+
dependent: :destroy,
11+
inverse_of: :promotion_rule
1012
has_many :stores, through: :promotion_rule_stores, class_name: "Spree::Store"
1113

1214
def preload_relations

legacy_promotions/app/models/spree/promotion/rules/taxon.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ module Spree
44
class Promotion < Spree::Base
55
module Rules
66
class Taxon < PromotionRule
7-
has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon', foreign_key: :promotion_rule_id,
8-
dependent: :destroy
7+
has_many :promotion_rule_taxons,
8+
class_name: 'Spree::PromotionRuleTaxon',
9+
foreign_key: :promotion_rule_id,
10+
dependent: :destroy,
11+
inverse_of: :promotion_rule
912
has_many :taxons, through: :promotion_rule_taxons, class_name: 'Spree::Taxon'
1013

1114
def preload_relations

legacy_promotions/app/models/spree/promotion/rules/user.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ module Spree
44
class Promotion < Spree::Base
55
module Rules
66
class User < PromotionRule
7-
has_many :promotion_rule_users, class_name: 'Spree::PromotionRuleUser',
8-
foreign_key: :promotion_rule_id,
9-
dependent: :destroy
7+
has_many :promotion_rule_users,
8+
class_name: 'Spree::PromotionRuleUser',
9+
foreign_key: :promotion_rule_id,
10+
dependent: :destroy,
11+
inverse_of: :promotion_rule
1012
has_many :users, through: :promotion_rule_users, class_name: Spree::UserClassHandle.new
1113

1214
def preload_relations

legacy_promotions/app/models/spree/promotion_category.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
module Spree
44
class PromotionCategory < Spree::Base
55
validates :name, presence: true
6-
has_many :promotions
6+
has_many :promotions, dependent: :nullify
77
end
88
end

legacy_promotions/app/models/spree/promotion_code.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Spree::PromotionCode < Spree::Base
44
belongs_to :promotion, inverse_of: :codes, optional: true
55
belongs_to :promotion_code_batch, class_name: "Spree::PromotionCodeBatch", optional: true
6-
has_many :adjustments
6+
has_many :adjustments, dependent: :restrict_with_error
77

88
before_validation :normalize_code
99

0 commit comments

Comments
 (0)