Skip to content

Commit

Permalink
Merge pull request #5744 from mamhoff/use-null-promo-config
Browse files Browse the repository at this point in the history
Use Null Promotion Configuration in core
  • Loading branch information
kennyadsl committed Jun 7, 2024
2 parents ea09d7e + 77a2aab commit 9e9abae
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions api/spec/lib/spree/api_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
end

it "can delete attributes" do
config.promotion_attributes << :name # name is not included by default with the NullPromotionConfiguration
expect(promotion_attributes).to include(:name)
config.promotion_attributes.delete(:name)
expect(promotion_attributes).not_to include(:name)
Expand Down
4 changes: 1 addition & 3 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,9 @@ def stock
# @!attribute [rw] promotions
# @return [Spree::Core::NullPromotionConfiguration] an object that conforms to the API of
# the example promotion configuration class Spree::Core::NullPromotionConfiguration.
# Currently, this defaults to the legacy promotion configuration, until that system is fully extracted
# to the `solidus_legacy_promotions` gem.
attr_writer :promotions
def promotions
@promotions ||= SolidusLegacyPromotions::Configuration.new
@promotions ||= Spree::Core::NullPromotionConfiguration.new
end

class << self
Expand Down
14 changes: 7 additions & 7 deletions core/spec/lib/spree/app_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
end

it "uses core's promotion configuration class by default" do
expect(prefs.promotions).to be_a SolidusLegacyPromotions::Configuration
expect(prefs.promotions).to be_a Spree::Core::NullPromotionConfiguration
end

context "deprecated preferences" do
Expand All @@ -52,23 +52,23 @@
end

it "uses order adjustments recalculator class by default" do
expect(prefs.promotion_adjuster_class).to eq Spree::Promotion::OrderAdjustmentsRecalculator
expect(prefs.promotion_adjuster_class).to eq Spree::NullPromotionAdjuster
end

it "uses promotion handler coupon class by default" do
expect(prefs.coupon_code_handler_class).to eq Spree::PromotionHandler::Coupon
expect(prefs.coupon_code_handler_class).to eq Spree::NullPromotionHandler
end

it "uses promotion handler shipping class by default" do
expect(prefs.shipping_promotion_handler_class).to eq Spree::PromotionHandler::Shipping
expect(prefs.shipping_promotion_handler_class).to eq Spree::NullPromotionHandler
end

it "uses promotion code batch mailer class by default" do
expect(prefs.promotion_code_batch_mailer_class).to eq Spree::PromotionCodeBatchMailer
expect(prefs.promotion_code_batch_mailer_class).to eq Spree::DeprecatedConfigurableClass
end

it "uses promotion chooser class by default" do
expect(prefs.promotion_chooser_class).to eq Spree::PromotionChooser
expect(prefs.promotion_chooser_class).to eq Spree::DeprecatedConfigurableClass
end
end

Expand Down Expand Up @@ -113,7 +113,7 @@

describe '#promotions' do
subject { prefs.promotions }
it { is_expected.to be_a SolidusLegacyPromotions::Configuration }
it { is_expected.to be_a Spree::Core::NullPromotionConfiguration }
end

describe '@default_country_iso_code' do
Expand Down
1 change: 1 addition & 0 deletions legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Engine < ::Rails::Engine

initializer "solidus_legacy_promotions", after: "spree.load_config_initializers" do
Spree::Config.order_contents_class = "Spree::OrderContents"
Spree::Config.promotions = SolidusLegacyPromotions::Configuration.new
end
end
end

0 comments on commit 9e9abae

Please sign in to comment.