mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Perform refresh of products cache when coordinator fee is changed
This commit is contained in:
@@ -50,6 +50,7 @@ module OpenFoodNetwork
|
||||
|
||||
|
||||
def self.enterprise_fee_changed(enterprise_fee)
|
||||
refresh_coordinator_fee enterprise_fee
|
||||
end
|
||||
|
||||
|
||||
@@ -74,6 +75,13 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
|
||||
def self.refresh_coordinator_fee(enterprise_fee)
|
||||
enterprise_fee.order_cycles.each do |order_cycle|
|
||||
order_cycle_changed order_cycle
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.refresh_cache(distributor, order_cycle)
|
||||
Delayed::Job.enqueue RefreshProductsCacheJob.new distributor.id, order_cycle.id
|
||||
end
|
||||
|
||||
@@ -164,6 +164,23 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
|
||||
describe "when an enterprise fee is changed" do
|
||||
let(:s) { create(:supplier_enterprise) }
|
||||
let(:c) { create(:distributor_enterprise) }
|
||||
let(:d1) { create(:distributor_enterprise) }
|
||||
let(:d2) { create(:distributor_enterprise) }
|
||||
let(:ef) { create(:enterprise_fee) }
|
||||
let(:ef_coord) { create(:enterprise_fee, order_cycles: [oc]) }
|
||||
let(:oc) { create(:open_order_cycle, coordinator: c) }
|
||||
|
||||
|
||||
it "updates order cycles when it's a coordinator fee" do
|
||||
ef_coord
|
||||
expect(ProductsCache).to receive(:order_cycle_changed).with(oc).once
|
||||
ProductsCache.enterprise_fee_changed ef_coord
|
||||
end
|
||||
end
|
||||
|
||||
describe "refreshing the cache" do
|
||||
let(:distributor) { double(:distributor, id: 123) }
|
||||
let(:order_cycle) { double(:order_cycle, id: 456) }
|
||||
|
||||
Reference in New Issue
Block a user