Touch primary taxon when a product's primary_taxon is changed

This commit is contained in:
Matt-Yorkley
2020-04-24 12:46:55 +02:00
parent 1b18808d21
commit eb5f8b85ff
2 changed files with 14 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ Spree::Product.class_eval do
has_many :option_types, through: :product_option_types, dependent: :destroy
belongs_to :supplier, class_name: 'Enterprise', touch: true
belongs_to :primary_taxon, class_name: 'Spree::Taxon'
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true
delegate_belongs_to :master, :unit_value, :unit_description
delegate :images_attributes=, :display_as=, to: :master

View File

@@ -30,11 +30,20 @@ module Spree
end
describe "touches" do
let!(:taxon) { create(:taxon) }
let!(:product) { create(:simple_product) }
let!(:taxon1) { create(:taxon) }
let!(:taxon2) { create(:taxon) }
let!(:taxon3) { create(:taxon) }
let!(:product) { create(:simple_product, primary_taxon: taxon1, taxons: [taxon1, taxon2]) }
it "is touched when applied to a product" do
expect{ product.taxons << taxon }.to change { taxon.reload.updated_at }
it "is touched when a taxon is applied to a product" do
expect{ product.taxons << taxon3 }.to change { taxon3.reload.updated_at }
end
it "is touched when assignment of primary_taxon on a product changes" do
expect do
product.primary_taxon = taxon2
product.save
end.to change { taxon2.reload.updated_at }
end
end
end