diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index d136c2b681..fe20fe5194 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -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 diff --git a/spec/models/spree/taxon_spec.rb b/spec/models/spree/taxon_spec.rb index b19f979d99..54a0069da9 100644 --- a/spec/models/spree/taxon_spec.rb +++ b/spec/models/spree/taxon_spec.rb @@ -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