mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-21 05:09:15 +00:00
Refresh products cache when taxons or classifications are changed or destroyed
This commit is contained in:
@@ -2,8 +2,8 @@ require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe Classification do
|
||||
let(:product) { create(:simple_product) }
|
||||
let(:taxon) { create(:taxon) }
|
||||
let!(:product) { create(:simple_product) }
|
||||
let!(:taxon) { create(:taxon) }
|
||||
let(:classification) { create(:classification, taxon: taxon, product: product) }
|
||||
|
||||
it "won't destroy if classification is the primary taxon" do
|
||||
@@ -11,5 +11,18 @@ module Spree
|
||||
classification.destroy.should be_false
|
||||
classification.errors.messages[:base].should == ["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"]
|
||||
end
|
||||
|
||||
describe "callbacks" do
|
||||
it "refreshes the products cache on save" do
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:product_changed).with(product)
|
||||
classification
|
||||
end
|
||||
|
||||
it "refreshes the products cache on destroy" do
|
||||
classification
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:product_changed).with(product)
|
||||
classification.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,21 @@ module Spree
|
||||
let(:t1) { create(:taxon) }
|
||||
let(:t2) { create(:taxon) }
|
||||
|
||||
describe "callbacks" do
|
||||
let(:product) { create(:simple_product, taxons: [t1]) }
|
||||
|
||||
it "refreshes the products cache on save" do
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:product_changed).with(product)
|
||||
t1.name = 'asdf'
|
||||
t1.save
|
||||
end
|
||||
|
||||
it "refreshes the products cache on destroy" do
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:product_changed).with(product)
|
||||
t1.destroy
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding all supplied taxons" do
|
||||
let!(:p1) { create(:simple_product, supplier: e, taxons: [t1, t2]) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user