Perform refresh of products cache when coordinator fee is changed

This commit is contained in:
Rohan Mitchell
2016-01-29 15:35:26 +11:00
parent 0c65d1ddd8
commit af7e3380d3
2 changed files with 25 additions and 0 deletions

View File

@@ -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

View File

@@ -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) }