mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-26 05:55:15 +00:00
Refresh products cache when coordinator fees are changed or destroyed
This commit is contained in:
@@ -1,4 +1,15 @@
|
||||
class CoordinatorFee < ActiveRecord::Base
|
||||
belongs_to :order_cycle
|
||||
belongs_to :enterprise_fee
|
||||
|
||||
after_save :refresh_products_cache
|
||||
after_destroy :refresh_products_cache
|
||||
|
||||
|
||||
private
|
||||
|
||||
def refresh_products_cache
|
||||
order_cycle.refresh_products_cache
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -241,6 +241,10 @@ class OrderCycle < ActiveRecord::Base
|
||||
coordinator.users.include? user
|
||||
end
|
||||
|
||||
def refresh_products_cache
|
||||
OpenFoodNetwork::ProductsCache.order_cycle_changed self
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
@@ -254,9 +258,4 @@ class OrderCycle < ActiveRecord::Base
|
||||
distributed_variants.include?(product.master) &&
|
||||
(product.variants & distributed_variants).empty?
|
||||
end
|
||||
|
||||
def refresh_products_cache
|
||||
OpenFoodNetwork::ProductsCache.order_cycle_changed self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
19
spec/models/coordinator_fee_spec.rb
Normal file
19
spec/models/coordinator_fee_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe CoordinatorFee do
|
||||
describe "products caching" do
|
||||
let(:order_cycle) { create(:simple_order_cycle) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee) }
|
||||
|
||||
it "refreshes the products cache on change" do
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:order_cycle_changed).with(order_cycle)
|
||||
order_cycle.coordinator_fees << enterprise_fee
|
||||
end
|
||||
|
||||
it "refreshes the products cache on destruction" do
|
||||
order_cycle.coordinator_fees << enterprise_fee
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:order_cycle_changed).with(order_cycle)
|
||||
order_cycle.coordinator_fee_refs.first.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user