Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-06-06 06:59:49 UTC using RuboCop version 1.76.0.
# on 2025-06-06 10:35:09 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
Expand All @@ -14,7 +14,7 @@ Gemspec/OrderedDependencies:
Exclude:
- 'core/solidus_core.gemspec'

# Offense count: 175
# Offense count: 179
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: with_first_argument, with_fixed_indentation
Expand Down Expand Up @@ -337,7 +337,7 @@ Rails/FilePath:
- 'core/lib/spree/testing_support/dummy_app.rb'
- 'sample/lib/spree/sample.rb'

# Offense count: 61
# Offense count: 59
# Configuration parameters: Include.
# Include: **/app/models/**/*.rb
Rails/HasManyOrHasOneDependent:
Expand Down Expand Up @@ -379,7 +379,7 @@ Rails/IndexWith:
- 'core/lib/spree/core/search/variant.rb'
- 'core/lib/spree/preferences/preferable.rb'

# Offense count: 35
# Offense count: 27
# Configuration parameters: IgnoreScopes, Include.
# Include: **/app/models/**/*.rb
Rails/InverseOf:
Expand Down
4 changes: 2 additions & 2 deletions promotions/app/models/solidus_promotions/benefit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Benefit < Spree::Base

belongs_to :promotion, inverse_of: :benefits
belongs_to :original_promotion_action, class_name: "Spree::PromotionAction", optional: true
has_many :adjustments, class_name: "Spree::Adjustment", as: :source
has_many :shipping_rate_discounts, class_name: "SolidusPromotions::ShippingRateDiscount", inverse_of: :benefit
has_many :adjustments, class_name: "Spree::Adjustment", as: :source, dependent: :restrict_with_error
has_many :shipping_rate_discounts, class_name: "SolidusPromotions::ShippingRateDiscount", inverse_of: :benefit, dependent: :restrict_with_error
has_many :conditions, class_name: "SolidusPromotions::Condition", inverse_of: :benefit, dependent: :destroy

scope :of_type, ->(type) { where(type: Array.wrap(type).map(&:to_s)) }
Expand Down
2 changes: 1 addition & 1 deletion promotions/app/models/solidus_promotions/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module SolidusPromotions
class Condition < Spree::Base
include Spree::Preferences::Persistable

belongs_to :benefit, class_name: "SolidusPromotions::Benefit", inverse_of: :conditions, optional: true
belongs_to :benefit, class_name: "SolidusPromotions::Benefit", inverse_of: :conditions
has_one :promotion, through: :benefit

scope :of_type, ->(type) { where(type: type) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module SolidusPromotions
class ConditionProduct < Spree::Base
belongs_to :condition, class_name: "SolidusPromotions::Condition", optional: true
belongs_to :product, class_name: "Spree::Product", optional: true
belongs_to :condition, class_name: "SolidusPromotions::Condition"
belongs_to :product, class_name: "Spree::Product"
end
end
4 changes: 2 additions & 2 deletions promotions/app/models/solidus_promotions/condition_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module SolidusPromotions
class ConditionStore < Spree::Base
belongs_to :condition, class_name: "SolidusPromotions::Condition", optional: true
belongs_to :store, class_name: "Spree::Store", optional: true
belongs_to :condition, class_name: "SolidusPromotions::Condition"
belongs_to :store, class_name: "Spree::Store"
end
end
4 changes: 2 additions & 2 deletions promotions/app/models/solidus_promotions/condition_taxon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module SolidusPromotions
class ConditionTaxon < Spree::Base
belongs_to :condition, class_name: "SolidusPromotions::Condition", optional: true
belongs_to :taxon, class_name: "Spree::Taxon", optional: true
belongs_to :condition, class_name: "SolidusPromotions::Condition"
belongs_to :taxon, class_name: "Spree::Taxon"
end
end
4 changes: 2 additions & 2 deletions promotions/app/models/solidus_promotions/condition_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module SolidusPromotions
class ConditionUser < Spree::Base
belongs_to :condition, class_name: "SolidusPromotions::Condition", optional: true
belongs_to :user, class_name: Spree::UserClassHandle.new, optional: true
belongs_to :condition, class_name: "SolidusPromotions::Condition"
belongs_to :user, class_name: Spree::UserClassHandle.new
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class LineItemProduct < Condition
has_many :condition_products,
dependent: :destroy,
foreign_key: :condition_id,
class_name: "SolidusPromotions::ConditionProduct"
class_name: "SolidusPromotions::ConditionProduct",
inverse_of: :condition
has_many :products,
class_name: "Spree::Product",
through: :condition_products
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ module Conditions
class LineItemTaxon < Condition
include LineItemLevelCondition

has_many :condition_taxons, class_name: "SolidusPromotions::ConditionTaxon", foreign_key: :condition_id,
dependent: :destroy
has_many :condition_taxons,
class_name: "SolidusPromotions::ConditionTaxon",
foreign_key: :condition_id,
dependent: :destroy,
inverse_of: :condition
has_many :taxons, through: :condition_taxons, class_name: "Spree::Taxon"

MATCH_POLICIES = %w[include exclude].freeze
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class Product < Condition
has_many :condition_products,
dependent: :destroy,
foreign_key: :condition_id,
class_name: "SolidusPromotions::ConditionProduct"
class_name: "SolidusPromotions::ConditionProduct",
inverse_of: :condition
has_many :products, class_name: "Spree::Product", through: :condition_products

def preload_relations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ module Conditions
class Store < Condition
include OrderLevelCondition

has_many :condition_stores, class_name: "SolidusPromotions::ConditionStore",
has_many :condition_stores,
class_name: "SolidusPromotions::ConditionStore",
foreign_key: :condition_id,
dependent: :destroy
dependent: :destroy,
inverse_of: :condition
has_many :stores, through: :condition_stores, class_name: "Spree::Store"

def preload_relations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ module Conditions
class Taxon < Condition
include LineItemApplicableOrderLevelCondition

has_many :condition_taxons, class_name: "SolidusPromotions::ConditionTaxon", foreign_key: :condition_id,
dependent: :destroy
has_many :condition_taxons,
class_name: "SolidusPromotions::ConditionTaxon",
foreign_key: :condition_id,
dependent: :destroy,
inverse_of: :condition
has_many :taxons, through: :condition_taxons, class_name: "Spree::Taxon"

def preload_relations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class User < Condition
has_many :condition_users,
class_name: "SolidusPromotions::ConditionUser",
foreign_key: :condition_id,
dependent: :destroy
dependent: :destroy,
inverse_of: :condition
has_many :users, through: :condition_users, class_name: Spree::UserClassHandle.new

def preload_relations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module SolidusPromotions
# 2. The specific code that they used
class OrderPromotion < Spree::Base
belongs_to :order, class_name: "Spree::Order"
belongs_to :promotion, -> { with_discarded }, class_name: "SolidusPromotions::Promotion"
belongs_to :promotion, -> { with_discarded }, class_name: "SolidusPromotions::Promotion", inverse_of: :order_promotions
belongs_to :promotion_code, class_name: "SolidusPromotions::PromotionCode", optional: true

validates :promotion_code, presence: true, if: :require_promotion_code?
Expand Down
7 changes: 5 additions & 2 deletions promotions/app/models/solidus_promotions/promotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ class Promotion < Spree::Base

include Spree::SoftDeletable

belongs_to :category, class_name: "SolidusPromotions::PromotionCategory",
foreign_key: :promotion_category_id, optional: true
belongs_to :category,
class_name: "SolidusPromotions::PromotionCategory",
foreign_key: :promotion_category_id,
optional: true,
inverse_of: :promotions
belongs_to :original_promotion, class_name: "Spree::Promotion", optional: true
has_many :benefits, class_name: "SolidusPromotions::Benefit", dependent: :destroy
has_many :conditions, through: :benefits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
require "rails_helper"

RSpec.describe SolidusPromotions::ConditionProduct do
it { is_expected.to belong_to(:product).optional }
it { is_expected.to belong_to(:condition).optional }
it { is_expected.to belong_to(:product) }
it { is_expected.to belong_to(:condition) }
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "rails_helper"

RSpec.describe SolidusPromotions::Condition do
it { is_expected.to belong_to(:benefit).optional }
it { is_expected.to belong_to(:benefit) }
let(:bad_test_condition_class) { Class.new(SolidusPromotions::Condition) }
let(:test_condition_class) do
Class.new(SolidusPromotions::Condition) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
require "rails_helper"

RSpec.describe SolidusPromotions::ConditionStore do
it { is_expected.to belong_to(:store).optional }
it { is_expected.to belong_to(:condition).optional }
it { is_expected.to belong_to(:store) }
it { is_expected.to belong_to(:condition) }
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
require "rails_helper"

RSpec.describe SolidusPromotions::ConditionTaxon do
it { is_expected.to belong_to(:taxon).optional }
it { is_expected.to belong_to(:condition).optional }
it { is_expected.to belong_to(:taxon) }
it { is_expected.to belong_to(:condition) }
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
require "rails_helper"

RSpec.describe SolidusPromotions::ConditionUser do
it { is_expected.to belong_to(:user).optional }
it { is_expected.to belong_to(:condition).optional }
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:condition) }
end
Loading