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

@@ -69,6 +69,16 @@ module Spree
lambda { variant.reload }.should_not raise_error
variant.deleted_at.should_not be_nil
end
it "doesn't delete the only variant of the product" do
product = create(:product)
variant = product.variants.first
spree_delete :soft_delete, {variant_id: variant.to_param, product_id: product.to_param, format: :json}
expect(variant.reload).to_not be_deleted
expect(assigns(:variant).errors[:product]).to include "must have at least one variant"
end
end
end
end

View File

@@ -1,7 +1,7 @@
require 'spec_helper'
module OpenFoodNetwork
xdescribe ProductsAndInventoryReport do
describe ProductsAndInventoryReport do
context "As a site admin" do
let(:user) do
user = create(:user)
@@ -105,7 +105,7 @@ module OpenFoodNetwork
it "should filter deleted products" do
product1 = create(:simple_product, supplier: supplier)
product2 = create(:simple_product, supplier: supplier)
product2.delete
product2.destroy
subject.filter(Spree::Variant.scoped).should match_array [product1.master, product1.variants.first]
end
describe "based on report type" do

View File

@@ -98,7 +98,7 @@ module OpenFoodNetwork
it "refreshes the cache based on exchanges the variant was in before destruction" do
expect(ProductsCache).to receive(:refresh_cache).with(distributor, oc)
product.delete
product.destroy
end
it "performs the cache refresh after the product has been removed from the order cycle" do
@@ -106,7 +106,7 @@ module OpenFoodNetwork
expect(product.reload.deleted_at).not_to be_nil
end
product.delete
product.destroy
end
end

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

View File

@@ -24,7 +24,7 @@ describe "Shop API", type: :request do
set_order order
v61.update_attribute(:count_on_hand, 1)
p6.delete
p6.destroy
v71.update_attribute(:count_on_hand, 1)
v41.update_attribute(:count_on_hand, 1)
v42.update_attribute(:count_on_hand, 0)

View File

@@ -1,3 +1,5 @@
require "spec_helper"
describe Api::Admin::ForOrderCycle::EnterpriseSerializer do
let(:coordinator) { create(:distributor_enterprise) }
let(:order_cycle) { double(:order_cycle, coordinator: coordinator) }
@@ -14,7 +16,7 @@ describe Api::Admin::ForOrderCycle::EnterpriseSerializer do
let(:serialized_enterprise) do
Api::Admin::ForOrderCycle::EnterpriseSerializer.new(
enterprise,
enterprise.reload, # load the products that were created after the enterprise
order_cycle: order_cycle,
spree_current_user: enterprise.owner
).to_json