Refresh cache when option type changed

This commit is contained in:
Rohan Mitchell
2016-02-26 09:59:16 +11:00
parent b5204a4820
commit 8928e461d4
2 changed files with 33 additions and 0 deletions

View 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

View 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