Merge pull request #3394 from mkllnk/3021-update-soft-delete

[Spree upgrade] 3021 update soft delete
This commit is contained in:
Pau Pérez Fabregat
2019-02-25 11:58:41 +01:00
committed by GitHub
18 changed files with 67 additions and 85 deletions

View File

@@ -55,15 +55,6 @@ module Spree
end
end
it "does not allow the last variant to be deleted" do
product = create(:simple_product)
expect(product.variants(:reload).length).to eq 1
v = product.variants.last
v.delete
expect(v.errors[:product]).to include "must have at least one variant"
end
context "when the product has variants" do
let(:product) do
product = create(:simple_product)
@@ -172,7 +163,7 @@ module Spree
it "refreshes the products cache on delete" do
expect(OpenFoodNetwork::ProductsCache).to receive(:product_deleted).with(product)
product.delete
product.destroy
end
# On destroy, all distributed variants are refreshed by a Variant around_destroy
@@ -185,11 +176,15 @@ module Spree
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 }
expect { product.destroy }.to change { supplier.reload.updated_at }
end
it "touches all distributors" do
expect { product.delete }.to change { distributor.reload.updated_at }
expect { product.destroy }.to change { distributor.reload.updated_at }
end
it "removes variants from order cycles" do
expect { product.destroy }.to change { ExchangeVariant.count }
end
end
@@ -701,13 +696,13 @@ module Spree
it "removes the master variant from all order cycles" do
e.variants << p.master
p.delete
p.destroy
e.variants(true).should be_empty
end
it "removes all other variants from order cycles" do
e.variants << v
p.delete
p.destroy
e.variants(true).should be_empty
end
end

View File

@@ -13,16 +13,6 @@ module Spree
end
describe "scopes" do
it "finds non-deleted variants" do
v_not_deleted = create(:variant)
v_deleted = create(:variant)
v_deleted.deleted_at = Time.zone.now
v_deleted.save
Spree::Variant.not_deleted.should include v_not_deleted
Spree::Variant.not_deleted.should_not include v_deleted
end
describe "finding variants in a distributor" do
let!(:d1) { create(:distributor_enterprise) }
let!(:d2) { create(:distributor_enterprise) }
@@ -535,22 +525,5 @@ module Spree
v.destroy
e.reload.variant_ids.should be_empty
end
context "as the last variant of a product" do
let!(:extra_variant) { create(:variant) }
let!(:product) { extra_variant.product }
let!(:first_variant) { product.variants.first }
before { product.reload }
it "cannot be deleted" do
expect(product.variants.length).to eq 2
expect(extra_variant.delete).to eq extra_variant
expect(product.variants(:reload).length).to eq 1
expect(first_variant.delete).to be false
expect(product.variants(:reload).length).to eq 1
expect(first_variant.errors[:product]).to include "must have at least one variant"
end
end
end
end