Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dependent: :destroy to Spree::Order#friendly_promotions #12

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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