From 7c7f3708a8319b7d85b8b715d6b3ca7a7812e4f4 Mon Sep 17 00:00:00 2001 From: Edwin Cruz Date: Tue, 26 Nov 2019 08:51:07 -0600 Subject: [PATCH] Fixing product discard and classifications issue When removing a product via discard, it was destroying all classifications via delete_all, acts as list callbacks were not called leaving gaps in position. --- core/app/models/spree/product.rb | 2 +- core/spec/models/spree/classification_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index a5123dc70bc..1b9cf3e6b92 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -25,7 +25,7 @@ class Product < Spree::Base variants_including_master.discard_all self.product_option_types = [] self.product_properties = [] - self.classifications = [] + self.classifications.destroy_all self.product_promotion_rules = [] end diff --git a/core/spec/models/spree/classification_spec.rb b/core/spec/models/spree/classification_spec.rb index 9af2e00cb93..5013653766a 100644 --- a/core/spec/models/spree/classification_spec.rb +++ b/core/spec/models/spree/classification_spec.rb @@ -44,6 +44,18 @@ def positions_to_be_valid(taxon) end end + context "Discard'ing a product" do + before :each do + element = taxon_with_5_products.products[1] + expect(element.classifications.first.position).to eq(2) + element.discard + end + + it "resets positions" do + expect positions_to_be_valid(taxon_with_5_products) + end + end + context "replacing taxon's products" do before :each do products = taxon_with_5_products.products.to_a