Touch taxon when a taxon is applied to a product

This commit is contained in:
Matt-Yorkley
2020-04-21 10:45:57 +02:00
parent ac166f3590
commit 6ef345c5d8
2 changed files with 10 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
Spree::Classification.class_eval do
belongs_to :product, class_name: "Spree::Product", touch: true
belongs_to :taxon, class_name: "Spree::Taxon", touch: true
before_destroy :dont_destroy_if_primary_taxon

View File

@@ -28,5 +28,14 @@ module Spree
expect(Taxon.distributed_taxons(:current)).to eq(e.id => Set.new([t1.id]))
end
end
describe "touches" do
let!(:taxon) { create(:taxon) }
let!(:product) { create(:simple_product) }
it "is touched when applied to a product" do
expect{ product.taxons << taxon }.to change { taxon.reload.updated_at }
end
end
end
end