mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-22 05:18:51 +00:00
When a product is deleted, touch the supplier and distributors
This commit is contained in:
@@ -188,6 +188,10 @@ Spree::Product.class_eval do
|
||||
def delete_with_delete_from_order_cycles
|
||||
transaction do
|
||||
OpenFoodNetwork::ProductsCache.product_deleted(self) do
|
||||
# Touch supplier and distributors as we would on #destroy
|
||||
self.supplier.touch
|
||||
touch_distributors
|
||||
|
||||
ExchangeVariant.where('exchange_variants.variant_id IN (?)', self.variants_including_master_and_deleted).destroy_all
|
||||
|
||||
delete_without_delete_from_order_cycles
|
||||
|
||||
@@ -177,6 +177,21 @@ module Spree
|
||||
|
||||
# On destroy, all distributed variants are refreshed by a Variant around_destroy
|
||||
# callback, so we don't need to do anything on the product model.
|
||||
|
||||
describe "touching affected enterprises when the product is deleted" do
|
||||
let(:product) { create(:simple_product) }
|
||||
let(:supplier) { product.supplier }
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:oc) { create(:simple_order_cycle, distributors: [distributor], variants: [product.variants.first]) }
|
||||
|
||||
it "touches the supplier" do
|
||||
expect { product.delete }.to change { supplier.reload.updated_at }
|
||||
end
|
||||
|
||||
it "touches all distributors" do
|
||||
expect { product.delete }.to change { distributor.reload.updated_at }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "scopes" do
|
||||
|
||||
Reference in New Issue
Block a user