mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Touch primary taxon when a product's primary_taxon is changed
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user