Skip to content

Commit

Permalink
Add dependent: :destroy to Spree::Order#friendly_promotions
Browse files Browse the repository at this point in the history
This is the same change as in
solidusio#5411
  • Loading branch information
mamhoff authored and Astr0surf3r committed Nov 14, 2024
1 parent 2c690ae commit 29bda57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions friendly_promotions/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 29bda57

Please sign in to comment.