diff --git a/friendly_promotions/app/decorators/models/solidus_friendly_promotions/order_decorator.rb b/friendly_promotions/app/decorators/models/solidus_friendly_promotions/order_decorator.rb index a70817c8a4e..f6130deff41 100644 --- a/friendly_promotions/app/decorators/models/solidus_friendly_promotions/order_decorator.rb +++ b/friendly_promotions/app/decorators/models/solidus_friendly_promotions/order_decorator.rb @@ -5,6 +5,7 @@ module OrderDecorator def self.prepended(base) base.has_many :friendly_order_promotions, class_name: "SolidusFriendlyPromotions::OrderPromotion", + dependent: :destroy, inverse_of: :order base.has_many :friendly_promotions, through: :friendly_order_promotions, source: :promotion end diff --git a/friendly_promotions/spec/models/spree/order_spec.rb b/friendly_promotions/spec/models/spree/order_spec.rb index 15ee8d76024..6be2cbff349 100644 --- a/friendly_promotions/spec/models/spree/order_spec.rb +++ b/friendly_promotions/spec/models/spree/order_spec.rb @@ -19,4 +19,18 @@ subject end end + + describe "order deletion" do + let(:order) { create(:order) } + let(:promotion) { create(:friendly_promotion) } + + subject { order.destroy } + before do + order.friendly_promotions << promotion + end + + it "deletes join table entries when deleting an order" do + expect { subject }.to change { SolidusFriendlyPromotions::OrderPromotion.count }.from(1).to(0) + end + end end