WIP: Delete ExchangeVariants when product is soft-deleted

This commit is contained in:
Rohan Mitchell
2014-06-06 14:52:26 +10:00
parent c21d5cc3dc
commit 083220089f
2 changed files with 28 additions and 1 deletions

View File

@@ -147,6 +147,13 @@ Spree::Product.class_eval do
end
end
def delete_with_delete_from_order_cycles
delete_without_delete_from_order_cycles
ExchangeVariant.where('exchange_variants.variant_id IN (?)', self.variants_including_master_and_deleted).destroy_all
end
alias_method_chain :delete, :delete_from_order_cycles
private

View File

@@ -580,7 +580,7 @@ module Spree
end
end
describe "Taxons" do
describe "taxons" do
let(:taxon1) { create(:taxon) }
let(:taxon2) { create(:taxon) }
let(:product) { create(:simple_product) }
@@ -589,5 +589,25 @@ module Spree
product.taxons.should == [product.primary_taxon]
end
end
describe "deletion" do
let(:p) { create(:simple_product) }
let(:v) { create(:variant, product: p) }
let(:oc) { create(:simple_order_cycle) }
let(:s) { create(:supplier_enterprise) }
let(:e) { create(:exchange, order_cycle: oc, incoming: true, sender: s, receiver: oc.coordinator) }
it "removes the master variant from all order cycles" do
e.variants << p.master
p.delete
e.variants(true).should be_empty
end
it "removes all other variants from order cycles" do
e.variants << v
p.delete
e.variants(true).should be_empty
end
end
end
end