diff --git a/core/app/models/spree/promotion_handler/shipping.rb b/core/app/models/spree/promotion_handler/shipping.rb index ac3c0c08341..694cf383a6d 100644 --- a/core/app/models/spree/promotion_handler/shipping.rb +++ b/core/app/models/spree/promotion_handler/shipping.rb @@ -18,7 +18,9 @@ def activate end not_connected_automatic_promotions.each do |promotion| - promotion.activate(order: order) + if promotion.eligible?(order) + promotion.activate(order: order) + end end end diff --git a/core/spec/models/spree/promotion_handler/shipping_spec.rb b/core/spec/models/spree/promotion_handler/shipping_spec.rb index b0ec7eb6462..4ee28a0a803 100644 --- a/core/spec/models/spree/promotion_handler/shipping_spec.rb +++ b/core/spec/models/spree/promotion_handler/shipping_spec.rb @@ -13,8 +13,20 @@ module PromotionHandler context 'with apply_automatically' do let!(:promotion) { create(:promotion, apply_automatically: true, promotion_actions: [action]) } - it "creates the adjustment" do - expect { subject.activate }.to change { shipment.adjustments.count }.by(1) + context 'for eligible promotion' do + it "creates the adjustment" do + expect { subject.activate }.to change { shipment.adjustments.count }.by(1) + end + end + + context 'for ineligible promotion' do + let!(:promotion) do + create(:promotion, :with_item_total_rule, item_total_threshold_amount: 1_000, apply_automatically: true, promotion_actions: [action]) + end + + it "does not create the adjustment" do + expect { subject.activate }.to change { shipment.adjustments.count }.by(0) + end end end