mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Refresh cache when option type changed
This commit is contained in:
13
app/models/spree/option_type_decorator.rb
Normal file
13
app/models/spree/option_type_decorator.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Spree
|
||||
OptionType.class_eval do
|
||||
has_many :products, through: :product_option_types
|
||||
after_save :refresh_products_cache
|
||||
|
||||
|
||||
private
|
||||
|
||||
def refresh_products_cache
|
||||
products(:reload).each &:refresh_products_cache
|
||||
end
|
||||
end
|
||||
end
|
||||
20
spec/models/spree/option_type_spec.rb
Normal file
20
spec/models/spree/option_type_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe OptionType do
|
||||
describe "products cache" do
|
||||
let!(:product) { create(:simple_product, option_types: [option_type]) }
|
||||
let(:option_type) { create(:option_type) }
|
||||
|
||||
before { option_type.reload }
|
||||
|
||||
it "refreshes the products cache on change, via product" do
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:product_changed).with(product)
|
||||
option_type.name = 'foo'
|
||||
option_type.save!
|
||||
end
|
||||
|
||||
# When a OptionType is destroyed, the destruction of the OptionValues refreshes the cache
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user