diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index 781fee27007..0cae1e65fab 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -104,7 +104,7 @@ def states foreign_key: :order_id, dependent: :destroy, inverse_of: :order - has_many :order_promotions, class_name: 'Spree::OrderPromotion' + has_many :order_promotions, class_name: 'Spree::OrderPromotion', dependent: :destroy has_many :promotions, through: :order_promotions # Payments diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rb index ab94e5df35e..387aab6fb71 100644 --- a/core/spec/models/spree/order_spec.rb +++ b/core/spec/models/spree/order_spec.rb @@ -1818,4 +1818,18 @@ def validate(line_item) end end end + + describe "order deletion" do + let(:order) { create(:order) } + let(:promotion) { create(:promotion) } + + subject { order.destroy } + before do + order.promotions << promotion + end + + it "deletes join table entries when deleting an order" do + expect { subject }.to change { Spree::OrderPromotion.count }.from(1).to(0) + end + end end