Skip to content

Commit

Permalink
Fixing product discard and classifications issue
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
softr8 committed Nov 26, 2019
1 parent bdb3c43 commit 7c7f370
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions core/spec/models/spree/classification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c7f370

Please sign in to comment.